无法为 JSP 加载类 [英] Unable to load class for JSP

查看:24
本文介绍了无法为 JSP 加载类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

异常堆栈跟踪

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)

我的redirect.jsp文件内容

My redirect.jsp file contents

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<% response.sendRedirect("user/list.htm"); %>

推荐答案

在 servletcontainer 的掩护下,JSP 在执行之前被编译为 Java 类.

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

异常

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

意味着您的 webcontent 文件夹根目录中的 redirect.jsp 文件未能编译,这通常意味着它在 scriptlets 中包含一些原始 Java 代码><% %> 包含语法错误.您需要修复这些语法错误,以便 servletcontainer 可以编译这些 JSP 文件.然而,普遍的共识是 scriptlets 是一种糟糕的做法.您应该考虑该 Java 代码是否更好地属于由 ServletFilter 控制的完整 Java 类.

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.

另一个可能的原因是servletcontainer的工作缓存被弄乱了.使用糟糕的 IDE 插件进行开发时可能会发生这种情况.您想清理工作缓存.例如,在 Eclipse 中,您可以通过右键单击服务器并选择 Clean 来完成此操作.否则,必须通过删除相关 servletcontainer 的工作缓存中的所有内容来手动完成.例如,对于 Tomcat,它就是 /work 文件夹中的所有内容.

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.

这篇关于无法为 JSP 加载类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆