javaweb报错org.apache.jasper.JasperException: Unable to compile class for JSP
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javaweb报错org.apache.jasper.JasperException: Unable to compile class for JSP相关的知识,希望对你有一定的参考价值。
报错内容如下,找了一天没找到问题,包也导了,但就是没法实例化。
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 9 in the jsp file: /WebRoot/emp_in.jsp
Emp cannot be resolved to a type
6: <%request.setCharacterEncoding("GBK");%>
7: <body>
8: <%
9: Emp emp = new Emp();
10: emp.setEmpno(Integer.parseInt(request.getParameter("empno")));
11: emp.setEname(request.getParameter("ename"));
12: emp.setJob(request.getParameter("job"));
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:102)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:331)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:469)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
这是JSP的代码。javaweb包下有Emp类
<%@page language="java" contentType="text/html" pageEncoding="GBK"%>
<%@page import= "javaweb.*"%>
<%-- <%@page import= "java.text.*"%> --%>
<html>
<head><title>员工管理</title></head>
<%request.setCharacterEncoding("GBK");%>
<body>
<%
Emp emp = new Emp();
emp.setEmpno(Integer.parseInt(request.getParameter("empno")));
emp.setEname(request.getParameter("ename"));
emp.setJob(request.getParameter("job"));
emp.setSal(Float.parseFloat(request.getParameter("sal")));
try
if(DAOFactory.getIEmpDAOInstance().doCreate(emp))
%>
<h3>雇员信息添加成功!</h3>
<%
else
%>
<h3>雇员信息添加失败!</h3>
<%
catch(Exception e)
e.printStackTrace();
%>
</body>
</html>
(最近经常在论坛上看到问这个错误的朋友,这几天不下于4次了,在网上搜集整理一下,大家参考一下)
1,检查是否将classpath设置错误:正确的为.;%java_home%/lib/rt.jar;%java_home%/lib/tools.jar <!--java_home is your jdk directory-->
2,This can usually be solved by copying manually $JAVA_HOME/lib/tools.jar from the JDK
to the common/lib directory of the Tomcat server, followed by a Tomcat restart.
看到了吗?
把jdk安装目录下的lib/tools.jar拷贝到tomcat安装目录下的common/lib目录下,然后重启tomcat,试试 。
3,设置tomcat的字符集为GBK,预防乱码的产生:F:/Tomcat 5.0/conf目录下的server.xml中增加一个参数URIEncoding="GBK"
for example: <Connector URIEncoding="GBK"
port="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true" />
4,增大tomcat的jvm内存使用参数:在F:/Tomcat 5.0/bin目录下的catalina.bat文件中增加set JAVA_OPTS=-Xms256m -Xmx512m
for example: the first word is added by us.
set JAVA_OPTS=-Xms384m -Xmx768m
set _EXECJAVA=%_RUNJAVA%
set MAINCLASS=org.apache.catalina.startup.Bootstrap
set ACTION=start
set SECURITY_POLICY_FILE=
set DEBUG_OPTS=
set JPDA=追问
粘贴来的吧,我也试过了,还是不行。
参考技术B 我也遇到了类似问题,问题产生的原因是jdk版本和tomcat版本不一致,将两者的版本换成一致,我的问题就解决了。希望对你有帮助。以上是关于javaweb报错org.apache.jasper.JasperException: Unable to compile class for JSP的主要内容,如果未能解决你的问题,请参考以下文章
关于intellij idea 中javaweb项目中使用jstl报错500错误问题
JavaWeb:报错信息The superclass "javax.servlet.http.HttpServlet" was not found on the Java Buil
JavaWeb: 报错信息The superclass "javax.servlet.http.HttpServlet" was not found on the Java Bui