Tomcat出现了Unable to compile class for JSP等错误

tomcat出现了Unable to compile class for JSP等错误

解决办法:

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 -Xmx512mfor 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=

5.tomcat版本太高,把tomcat8换为tomcat7以前的低版本。

 

代码没有错,tomcat就是编译不了。一直报错。 Unable to compile class for JSP: An error occurred at line: [15] in the generated java file: [E:\Java web\apache-tomcat-8.5.43\work\Catalina\localhost\shixunzy2\org\apache\jsp\buyForm_jsp.java] Only a type can be imported. vo.Book resolves to a package An error occurred at line: [14] in the jsp file: [/buyForm.jsp] Book cannot be resolved to a type 11: <% 12: String bookno=request.getParameter("bookno"); 13: HashMap allbook=(HashMap)session.getAttribute("allbook"); 14: Book book=(Book)allbook.get(bookno); 15: %> 16: 娆㈣繋璐拱<%=book.getBookname() %> 17: <form action="/shixunzy/servlet/AddServlet" method="post"> An error occurred at line: [14] in the jsp file: [/buyForm.jsp] Book cannot be resolved to a type 11: <% 12: String bookno=request.getParameter("bookno"); 13: HashMap allbook=(HashMap)session.getAttribute("allbook"); 14: Book book=(Book)allbook.get(bookno); 15: %> 16: 娆㈣繋璐拱<%=book.getBookname() %> 17: <form action="/shixunzy/servlet/AddServlet" method="post"> Stacktrace: at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:102) at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:212) at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:549) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:378) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:350) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:334) at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:595) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:399) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330) at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:660) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:798) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:808) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Unknown Source)
最近在学习jsp,使用tomcat9和jdk12,第一个jsp程序,编写了一个MyOk.java文件代码如下: ``` public class MyOk{ public String getTXT(){ String str = "you are success"; return str; } } ``` 通过javac编译后生成MyOk.class文件,将该文件拷贝至webapps/testok/WEB-INF/classes目录中,并在testok目录下编写testok.jsp,代码如下: ``` <%@ page import="MyOk"%> <!DOCTYPE html> <html> <head> <title></title> </head> <body> <p>this is my first jsp program</p> </body> </html> ``` WEB-INF文件中的web.xml文件内容如下: ``` <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0" metadata-complete="true"> <display-name>Tomcat Documentation</display-name> <description> Tomcat Documentation. </description> </web-app> ``` 在浏览器中输入“localhost:8080”可以正常打开tomcat页面, 但输入“localhost:8080/testok/testok.jsp”访问时报出以下错误: ``` HTTP Status 500 – Internal Server Error Type 异常报告 消息 Unable to compile class for JSP: 描述 服务器遇到一个意外的情况,阻止它完成请求。 ``` ![图片说明](https://img-ask.csdn.net/upload/201909/19/1568871907_833390.jpg) 试过百度上的一些方法,但无论怎么设置,都一直出现这个错误,实在没有办法,求教各位大神们,谢谢啦!!
©️2020 CSDN 皮肤主题: 创作都市 设计师:CSDN官方博客 返回首页