Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to load class for JSP

Tags:

java

jsp

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"); %>
like image 827
theJava Avatar asked Dec 21 '10 16:12

theJava


1 Answers

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.

like image 175
BalusC Avatar answered Oct 08 '22 17:10

BalusC