對於使用在JSP頁面之外定義的外部Java類的所有JSP頁面,我總是收到錯誤HTTP狀態500。下面是碼Tomcat/Windows 7上的HTTP狀態500
的index.jsp
<%@page import="mypack.sou" %>
<%@page contentType="text/html" 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>Hello World!</h1>
<%
sou o=new sou();
int r=o.hi();
out.println(r);
%>
</body>
</html>
sou.java下包mypack
package mypack;
public class sou {
public int hi()
{
return 0;
}
}
錯誤:
type Exception report
"message Unable to compile class for JSP: An error occurred at line: 14 in the generated java file Only a type can be imported. mypack.sou resolves to a package An error occurred at line: 18 in the jsp file: /web/index.jsp sou cannot be resolved to a type 15:
Hello World!
16: 17: <% 18: sou o=new sou(); 19: int r=o.hi(); 20: out.println(r); 21: %> An error occurred at line: 18 in the jsp file: /web/index.jsp sou cannot be resolved to a type 15:Hello World!
16: 17: <% 18: sou o=new sou(); 19: int r=o.hi(); 20: out.println(r); 21: %> Stacktrace:description The server encountered an internal error (Unable to compile class for JSP: An error occurred at line: 14 in the generated java file Only a type can be imported. mypack.sou resolves to a package An error occurred at line: 18 in the jsp file: /web/index.jsp sou cannot be resolved to a type 15:
Hello World!
16: 17: <% 18: sou o=new sou(); 19: int r=o.hi(); 20: out.println(r); 21: %> An error occurred at line: 18 in the jsp file: /web/index.jsp sou cannot be resolved to a type 15:Hello World!
16: 17: <% 18: sou o=new sou(); 19: int r=o.hi(); 20: out.println(r); 21: %> Stacktrace:) that prevented it from fulfilling this request."
目錄結構
- 的webapps
| app
| _ index.jsp
| _ WEB-INF
...... | _類
............. | _ mypack
.................... | _sou.class,test.war,mypack.jar
系統信息:的Win 7旗艦版X64,Apache Tomcat上7.0.29
Java版本 「1.7.0_02」
的Java (TM)SE運行時環境(內部版本1.7.0_02-b13)
Java HotSpot(TM)客戶端VM(內部版本22.0-b10,混合模式,共享)
Tomcat目錄具有完全權限!
我不得不轉移到GlassFish,其中相同的代碼工作!但問題仍然存在與Tomcat
問題是該死的,我知道。但是這不應該被稱爲CODEREVIEW,因爲它不是與我相信的代碼相關的問題。 **在-1投票前寫下您的理由,以便我可以糾正自己從未來的類似錯誤**! – Sourav 2012-08-12 16:35:32
您在瀏覽器上獲得的確切輸出是什麼? – 2012-08-12 17:21:15
我在錯誤部分 – Sourav 2012-08-12 17:22:33