HTTP Status 500 - Unable to compile class for JSP
好的,有很多关于这个错误的文章,我还是个新手。 我播种这个错误可能是由于某种不同的原因引起的,这是我(可能是愚蠢的或已经存在的)原因:
它找不到类,显然是从NetBeans导入的。
<%@ page import="mypack.Display" %>
事实上,如果我查看缓存文件“index_jsp.java”,问题就在于“ import mypack.Display; ”。 我的问题与此What causes this jsp Error 500?非常相似,区别在于我没有将 mypack.Display 放入默认包中,然后我不知道为什么会出现此错误。
这是我的 index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1><% out.print("jsp class test");%></h1>
<%@ page import="mypack.Display" %>
<%
Display t = new Display();
t.test("Roby");
%>
</body>
</html>
这是简单的 Display.java
package mypack;
public class Display{
public void test(String msg){
System.out.println("My name is "+msg);
}
}
我的一位朋友说我应该将 servlet 配置到 web.xml 文件中的WEB-INF文件夹中,但查看样本我没有'我明白我是怎么做到的。 我是否必须将包映射到该文件中?
我将 Display.java 放在Netbeans正确采用的“mypack”包下,实际上如果我尝试在index.jsp和Display中更改类或包名称.java,编译器向我显示错误。
有人可以帮助我,以便更好地理解吗?
完整错误下方:
type Exception report
message Unable to compile class for JSP:
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 14 in the generated java file
Only a type can be imported. mypack.Display resolves to a package
An error occurred at line: 19 in the jsp file: /index.jsp
Display cannot be resolved to a type
16: <%--<jsp:useBean id="link" scope="application" class = "mypack.Display" />--%>
17: <%@ page import="mypack.Display" %>
18: <%
19: Display t = new Display();
20: t.test("Roby");
21: // out.println(outpt);
22: %>
An error occurred at line: 19 in the jsp file: /index.jsp
Display cannot be resolved to a type
16: <%--<jsp:useBean id="link" scope="application" class = "mypack.Display" />--%>
17: <%@ page import="mypack.Display" %>
18: <%
19: Display t = new Display();
20: t.test("Roby");
21: // out.println(outpt);
22: %>
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: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: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:728)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.35 logs.