对于使用在 JSP 页面之外定义的外部 Java 类的所有 JSP 页面,我不断收到错误HTTP 状态 500 。这是代码
索引.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>
包mypack下的sou.java
package mypack;
public class sou {
public int hi()
{
return 0;
}
}
错误:
类型异常报告
“消息无法为 JSP 编译类:在生成的 java 文件中的第 14 行发生错误只能导入一个类型。mypack.sou 解析为一个包在 jsp 文件中的第 18 行发生错误:/web/ index.jsp sou 无法解析为类型 15:
你好世界!
16:17:<%18:sou o=new sou(); 19: int r=o.hi(); 20: out.println(r); 21: %> jsp 文件中的第 18 行发生错误:/web/index.jsp sou 无法解析为类型 15:你好世界!
16:17:<%18:sou o=new sou(); 19: int r=o.hi(); 20: out.println(r); 21:%>堆栈跟踪:描述 服务器遇到内部错误 (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 generated java file Only a type can be imported. mypack.sou resolves to a package An error occurred at line: 18 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 generated java file Only a type can be imported. mypack.sou resolves to a package An error occurred at line: 18 in the generated java file Only a type can be imported. jsp 文件:/web/index.jsp sou 无法解析为类型 15:
你好世界!
16:17:<%18:sou o=new sou(); 19: int r=o.hi(); 20: out.println(r); 21: %> jsp 文件中的第 18 行发生错误:/web/index.jsp sou 无法解析为类型 15:你好世界!
16:17:<%18:sou o=new sou(); 19: int r=o.hi(); 20: out.println(r); 21: %> Stacktrace :) 阻止了它完成这个请求。”
目录结构
- 网络应用
| 应用
|_ index.jsp
|_WEB-INF
......|_类
........| _我的包
....................|_sou.class、test.war、mypack.jar
系统信息: Win 7 Ultimate X64、Apache Tomcat 7.0.29
java 版本“1.7.0_02”
Java(TM) SE Runtime Environment (build 1.7.0_02-b13)
Java HotSpot(TM) Client VM (build 22.0-b10, mixed mode , 分享)
Tomcat目录拥有完全权限!
我不得不搬到 GlassFish,在那里同样的代码可以工作!但是Tomcat仍然存在问题