HTTP Status 500 - Unable to compile class for JSP
わかりました、このエラーに関する記事はたくさんありますが、私はまだ初心者です。私は、このエラーがいくつかの異なる種類の理由によって引き起こされた可能性があると考えています.
明らかに NetBeans からインポートされたクラスが見つかりません。
<%@ page import="mypack.Display" %>
実際、キャッシュ ファイル「index_jsp.java」を見ると、問題は「import mypack.Display;」がある行にあります。私の問題はこれにとても似ていますこのjspエラー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);
}
}
私の友人は、サーブレットを WEB-INF フォルダーのweb.xmlファイルに構成する必要があると言いましたが、サンプルを見て、どうすればそれができるかわかりませんでした。パッケージをそのファイルにマッピングする必要がありますか?
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.