gpt4 book ai didi

java - JSP "cannot be resolved to a type", "unable to compile"

转载 作者:行者123 更新时间:2023-11-28 22:42:29 25 4
gpt4 key购买 nike

我做了一个 Tomcat 项目,但我遇到了问题;我不能使用自己的类(class)。这是一个例子:

MyContext/test.jsp

<%@page language="java" import="myPackage.*" %>
<%=new MyClass()%>

MyContext/WEB-INF/MyPackage/MyClass.java

package myPackage;
import java.util.*;

public class MyClass{
public String toString(){
return "this is the string from my class!";
}
}

目录树:

MyContext
|---test.jsp
`---WEB-INF
`---classes
`---myPackage
|---MyClass.class
`---MyClass.java

访问 MyContext/test.jsp 时出现错误:

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

An error occurred at line: 2 in the jsp file: /test.jsp
MyClass cannot be resolved to a type
1: <%@page language="java" import="myPackage.*" %>
2: <%=new MyClass()%>


Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:366)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:468)
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:657)
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:727)

我的环境是Ubuntu 服务器 14.04,Java 版本 1.7.0_55, Tomcat 7。

请帮帮我。

最佳答案

更改MyClass.java

package myPackage 更改为 MyPackage

关于java - JSP "cannot be resolved to a type", "unable to compile",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25179720/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com