Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Runtime error - Session cannot be resolved to a type

843834May 7 2009 — edited May 7 2009
Hello! I try to get JavaMail working, but all in vain.
The problem is I get such an error every time.
org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 29 in the jsp file: /SendMail.jsp
Session cannot be resolved to a type
26:    prop.put("mail.smtp.host",hostMail);
27:    prop.put("mail.smtp.user",fromEmail);
28:    prop.put("mail.smtp.auth","true");
29:    Session ses =  Session.getInstance(prop,null);
30:    ses.setDebug(true);
31:    MimeMessage msg = new MimeMessage(ses);
32:    MimeBodyPart m1 = new MimeBodyPart();


An error occurred at line: 29 in the jsp file: /SendMail.jsp
Session cannot be resolved
26:    prop.put("mail.smtp.host",hostMail);
27:    prop.put("mail.smtp.user",fromEmail);
28:    prop.put("mail.smtp.auth","true");
29:    Session ses =  Session.getInstance(prop,null);
30:    ses.setDebug(true);
31:    MimeMessage msg = new MimeMessage(ses);
32:    MimeBodyPart m1 = new MimeBodyPart();

Stacktrace:
	org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:93)
	org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
	org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:435)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:298)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:277)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:265)
	org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:302)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
I'm using Eclipse, so I've added external JARs there (activation.jar, mail.jar, mailapi.jar, pop3.jar, smtp.jar). In addition to this, the same libraries are in +/opt/jdk1.6.0_13/jre/lib/+.

I've imported javax.mail.*, java.util.*, javax.mail.internet.* in my JSP file. I tried to do a lot of manipulations. Also I tried to use different code examples, but the error in the line "Session.getInstance(props, null)" remains the same.
   Properties prop = new Properties();
   prop.put("mail.smtp.host",hostMail);
   prop.put("mail.smtp.user",fromEmail);
   prop.put("mail.smtp.auth","true");
   Session ses =  Session.getInstance(prop,null);
The same problem remains when I do this as a Servlet. Class compilation with javac occurs without errors.
Might the problem be in version compatibility? I use: ArchLinux, Tomcat 5.5, JavaMail 1.4.2.
Thanks in advance.

Edited by: Pavel_Z on May 7, 2009 4:55 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 4 2009
Added on May 7 2009
5 comments
3,767 views