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

问题描述

我正在使用最新的TomCat版本,并且最近安装了Eclipse Java EE版本,因此它也是最新版本.顺便说一句,我确实有最新版本的 JAVA SE (JDK).

I'm using the latest TomCat version and I've recently installed Eclipse Java EE version so it's also the latest version.Btw I do have the latest version of JAVA SE (JDK).

这是我的课程:

    package jsp.demo;

public class ClassForJSP {

    public static String lowerCase(String data) {
        return data.toLowerCase();
    }
}

这是我真正简单的jsp代码:

So this is my really simple jsp code:

<%@page import="jsp.demo.ClassForJSP"%>
<html>
<body>
    Let's make THIS STATEMENT lower case: <%= ClassForJSP.lowerCase("THIS STATEMENT") %>
</body>
</html>

我收到此错误:

消息无法为JSP编译类:

Message Unable to compile class for JSP:

说明服务器遇到意外状况,该状况是 阻止了该请求的执行.

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

org.apache.jasper.JasperException异常:无法编译类 对于JSP:

Exception org.apache.jasper.JasperException: Unable to compile class for JSP:

在生成的Java文件[D:\ Java]中的第[14]行发生错误 Projects.metadata.plugins \ org.eclipse.wst.server.core \ tmp0 \ work \ Catalina \ localhost \ jspdemo \ org \ apache \ jsp \ callJavaClass_jsp.java] 只能导入类型. jsp.demo.ClassForJSP解析为 包装

An error occurred at line: [14] in the generated java file: [D:\Java Projects.metadata.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\jspdemo\org\apache\jsp\callJavaClass_jsp.java] Only a type can be imported. jsp.demo.ClassForJSP resolves to a package

jsp文件[/callJavaClass.jsp]中的第[4]行发生错误: ClassForJSP无法解析1:<%@ page import ="jsp.demo.ClassForJSP"%> 2:3:4:让我们 本声明的小写字母:<%= ClassForJSP.lowerCase(本声明") %> 5:6:

An error occurred at line: [4] in the jsp file: [/callJavaClass.jsp] ClassForJSP cannot be resolved 1: <%@page import="jsp.demo.ClassForJSP"%> 2: 3: 4: Let's make THIS STATEMENT lower case: <%= ClassForJSP.lowerCase("THIS STATEMENT") %> 5: 6:

Stacktrace: org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103) org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:213) org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:473) org.apache.jasper.compiler.Compiler.compile(Compiler.java:392) org.apache.jasper.compiler.Compiler.compile(Compiler.java:362) org.apache.jasper.compiler.Compiler.compile(Compiler.java:346) org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:603) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:399) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330) javax.servlet.http.HttpServlet.service(HttpServlet.java:741) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

Stacktrace: org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103) org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:213) org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:473) org.apache.jasper.compiler.Compiler.compile(Compiler.java:392) org.apache.jasper.compiler.Compiler.compile(Compiler.java:362) org.apache.jasper.compiler.Compiler.compile(Compiler.java:346) org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:603) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:399) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330) javax.servlet.http.HttpServlet.service(HttpServlet.java:741) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

注意服务器中提供了根本原因的完整堆栈跟踪 日志.

Note The full stack trace of the root cause is available in the server logs.

Apache Tomcat/9.0.14

Apache Tomcat/9.0.14

推荐答案

此消息告诉您:

Only a type can be imported. jsp.demo.ClassForJSP resolves to a package

您的Java类的源代码指示该软件包为jsp.demo.但是在运行时,JSP编译器发现了一个名为jsp.demo.ClassForJSP的包(即类路径上的目录).

The source code of your Java class indicates that the package is jsp.demo. But at runtime, the JSP compiler has found a package (i.e. a directory on the classpath) whose name is jsp.demo.ClassForJSP.

很显然,类路径出了问题……并且JSP编译器发出了一个红色标记.

Clearly, something is wrong with the classpath ... and the JSP compiler has raised a red flag.

怎么来?

  • 也许您正在使用部署到服务器的Web应用程序中的陈旧" JAR文件?
  • 也许您错过了构建或部署步骤?
  • 也许您手动组装了JAR文件或包含该文件的WAR文件,并弄错了结构?
  • 也许您正在Tomcat服务器上进行实时"操作,并且已经将".class"文件复制到了错误的位置?
  • 可能还有其他事情吗?

您需要亲自查看所有这些可能性.

You will need to look at all of these possibilities yourself.

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

08-18 18:35