org.apache.jasper.JasperException: Unable to compile class for JSP

别来无恙 提交于 2019-12-10 18:55:13

问题


I'm new to using libraries, but i need to be able to send an email to users who forget their password. I'm trying to use the JavaMail and Apache Commons Email to implement this. However, I think I must be importing the libraries wrongly.

When I try to send an email, I get the following message:

Apr 17, 2011 11:54:33 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 60 in the jsp file: /sendpw.jsp
The type javax.mail.Authenticator cannot be resolved. It is indirectly referenced from required .class files

the code:

57:                 EmailAuthentication ea = new EmailAuthentication();
58:                 String authUser = ea.getUser();
59:                 String authPw = ea.getPw();
60:                 email.setAuthenticator(new DefaultAuthenticator(authUser, authPw));
61:                 email.setTLS(true);
62:                 email.setFrom(authUser+"@gmail.com");
63:                 email.setSubject("Your Last Love Password");

Stacktrace:

at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:349)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:589)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1555)
at java.lang.Thread.run(Thread.java:662)

I've tried a few things:

  1. Copied the org.apache.commons.mail folder containing all the .java files into the source file of my netbeans project, and then adding the javamail library to the project. This worked the first time and I was able to send a few successful emails, but someway down the road it stopped working (perhaps because I cleaned and built the project) and i get the above message.

  2. Created a new library with the jar files in the bin version of the commons-email-1.2 just like i did with the javamail, and add it to the project. This one doesnt seem to work, because when I open up the defaultauthenticator.java, it cannot import javax.mail.Authenticator, although i've added both libraries to the same netbeans project.

  3. Added mail.jar and all the other .jars (dsn.jar, imap.jar, pop3.jar etc) from javamail into the same library as the apache common-email-1.2, meaning 2 classpath files (mail.jar and commons-email-1.2.jar) and 6 source files. This time, there was no error in the defaultauthenticator.java but still cannot send any email (same server error as above).

The part of the code involved is:

           HtmlEmail email = new HtmlEmail();

            email.setHostName("smtp.gmail.com");

            email.setSmtpPort(587);

            ......

            email.setAuthenticator(new DefaultAuthenticator(authUser, authPw));

            email.setTLS(true);

            email.setFrom(authUser+"@gmail.com");

            email.setSubject("Your Password");

....

I am using Netbeans 6.9.1, tomcat 6.0.26.

What am I doing wrongly?


回答1:


You need the mail.jar - and probably the activation.jar - library to be accessible from within your web application, so they should be either

  • in the tomcat6/lib, or
  • in the yourwebapp/WEB-INF/lib

folder.




回答2:


If someone is using Maven Project and faces this error, then remove jasper properties and dependency from Pom.xml.



来源:https://stackoverflow.com/questions/5691597/org-apache-jasper-jasperexception-unable-to-compile-class-for-jsp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!