Tomcat/Windows 7上的HTTP状态500

问题描述:

对于使用在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

+0

问题是该死的,我知道。但是这不应该被称为CODEREVIEW,因为它不是与我相信的代码相关的问题。 **在-1投票前写下您的理由,以便我可以纠正自己从未来的类似错误**! – Sourav 2012-08-12 16:35:32

+0

您在浏览器上获得的确切输出是什么? – 2012-08-12 17:21:15

+0

我在错误部分 – Sourav 2012-08-12 17:22:33

尝试添加“;”到您的进口声明。

修改如下:

<%@page import="mypack.sou;" %> 
<!DOCTYPE html> //Remove content type 


可能这看起来像一个奇怪的答案,但看到这个参考 https://stackoverflow.com/a/1858635/586836

编辑:
否则:
尝试在编译的java文件一个类手动,然后把它放在classes目录中并检查。

+0

没有工作!!! – Sourav 2012-08-12 17:40:03

+0

没有工作,再次! – Sourav 2012-08-12 17:57:12

尝试使用 mypack.sou而不是sou; 您必须在JSP内使用完全限定的类名称,因为Container将所有JSP转换为普通的旧Java Servlet代码。 或者你可以改为导入你的包裹:

<%@ page import=”mypack.*” %> 
+0

试过了,但没有效果。我认为代码没有错误,问题是与Win 7或Tomcat! – Sourav 2012-08-13 12:34:50