17

Exception stack trace

org.apache.jasper.JasperException: Unable to load class for JSP
 org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:599)
 org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:143)
 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:321)
 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
 org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

java.lang.ClassNotFoundException: org.apache.jsp.redirect_jsp
 java.net.URLClassLoader$1.run(Unknown Source)
 java.security.AccessController.doPrivileged(Native Method)
 java.net.URLClassLoader.findClass(Unknown Source)
 org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:131)
 org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:63)
 org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:597)
 org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:143)
 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:321)
 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
 org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

My redirect.jsp file contents

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<% response.sendRedirect("user/list.htm"); %>
Wesley
  • 10,652
  • 4
  • 37
  • 52
theJava
  • 14,620
  • 45
  • 131
  • 172

6 Answers6

39

Under the covers of the servletcontainer, JSP's are compiled to Java classes before they get executed.

The exception

java.lang.ClassNotFoundException: org.apache.jsp.redirect_jsp

means that the redirect.jsp file in the root of your webcontent folder failed to compile which in turn often means that it contains some raw Java code in scriptlets <% %> which contains syntax errors. You need to fix those syntax errors so that the servletcontainer can compile those JSP files. The general concensus is however that scriptlets are a poor practice. You should consider if that Java code doesn't better belong in a fullworthy Java class, controlled by a Servlet or a Filter.

Another possible cause is that the work cache of the servletcontainer is messed up. This can happen when developing with a poor IDE plugin. You'd like to clean the work cache. In for example Eclipse, you can do that by rightclick the server and choosing Clean. Otherwise it has to be done manually by deleting everything in work cache of the servletcontainer in question. In case of for example Tomcat, that's then everything in side its /work folder.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Just updated my redirect.jsp code.. is there any change need to be done – theJava Dec 21 '10 at 17:15
  • Had the same error and deleting everything from the /work directory solved my problem. Thanks BalusC!!! – Frank Apr 22 '13 at 11:33
  • I am getting this error with a tomcat 6 server.. There are no scriptlets in the redirect.jsp file and I tried removing everything from the /work folder. After reloading the page, I can see that the redirect_jsp.java file is re-created in the `/work` folder, but I keep getting the same errors. Any ideas on how to further debug this? – AlexBrand May 21 '13 at 12:42
  • it's not a syntax issue the jsp file was copied from another working tomcat instance, it is tomcat alone which is at fault – user3338098 Nov 05 '15 at 17:17
  • 1
    turns out the disk was full, which tomcat couldn't be bothered to report properly – user3338098 Nov 05 '15 at 17:26
  • I fixed this on ubuntu (openjdk7) by stopping tomcat7 then deleting /var/lib/tomcat7/work/Catalina/localhost/_/ After a day's debugging. – TimP Dec 21 '15 at 23:39
3

This can happen without apparent reason when you run out of disk space. Tomcat cant create the class file but goes ahead and inappropriately assumes it was successful, and then complains latter.

user3338098
  • 907
  • 1
  • 17
  • 38
1

Another reason for this exception might be lack of write permission. If tomcat was started on linux machine by a root user it will create work/ directory with owner root. If you will try to start tomcat with special user that has lesser permissions it will fail to compile JSP files because of that. So you might try two solutions:

  1. Change ownership of tomcat work folder using chown tomcat_user -R work/
  2. Remove work directory before starting tomcat as user with lesser permissions using rm -R work/
0

I had similar problem on the spring template Spring MVC hello world example,generated by IntelliJ. The InternalResourceViewResolver would not resolve the Hello_JSP.java file. I had to change it to following dependency

<dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> </dependency>

Hope it can help someone.

alexbt
  • 16,415
  • 6
  • 78
  • 87
Yoku
  • 307
  • 5
  • 16
0

I was getting this error because I had a JSP API dependency in my WAR's pom.xml:

<dependency>
  <groupId>javax.servlet.jsp</groupId>
  <artifactId>jsp-api</artifactId>
  <version>2.1</version>
  <scope>compile</scope>
</dependency>

Changing it to this fixed it:

<dependency>
  <groupId>javax.servlet.jsp</groupId>
  <artifactId>jsp-api</artifactId>
  <version>2.1</version>
  <scope>provided</scope>
</dependency>

One assumes this is due to a duplicate class being present during the compile phase. Without BalusC explaining it's a compilation issue I'd have never guessed!

Community
  • 1
  • 1
Simon Gibbs
  • 4,737
  • 6
  • 50
  • 80
0

I was also facing this problem which is due to library jar files like jetty-util-6.0.0rc0.jar, jasper-compiler-jdt-5.5.23.jar, jasperreports-3.0.0.jar. My answer may not be proper because right now I'm a beginner but at least you can try... Thank u,

OnaBai
  • 40,767
  • 6
  • 96
  • 125