我做错了什么?
我在 win 7 中将 Apache tomcat 7 作为服务运行
我的 jsp 代码 [...\webapps\test\index.jsp]
<jsp:useBean id="Counter" scope="session" class="aaa.Counter" />
<html>
<title>sfcsv</title>
<%
try{
int x = Counter.read_count(),z = Counter.get_id();
if(x%2==0)
out.println(x + " = even");
else
out.println(x + " = odd");
out.println(z);
}catch(Exception e){
out.println(e);
}
%>
</html>
java代码[..\webapps\test\WEB-INF\classes\aaa\Counter.java]
package aaa;
public class Counter {
private int count;
private static int instance_counter;
private final int id;
public Counter(){
instance_counter ++;
id = instance_counter;
count = 0;
}
public int read_count(){
return count++;
}
public int get_id(){
return id;
}
}
预期输出:
24 = even 1
我得到的输出:
24 = even
或者
HTTP Status 500 - Unable to compile class for JSP: An error occurred at line: 8 in the jsp file: /index.jsp The method get_id() is undefined for the type Counter 5: 6: <% 7: try{ 8: int x = Counter.read_count(),z = Counter.get_id(); 9: if(x%2==0) 10: out.println(x + " = even"); 11: else Stacktrace:
type Exception report
message Unable to compile class for JSP: An error occurred at line: 8 in the jsp file: /index.jsp The method get_id() is undefined for the type Counter 5: 6: <% 7: try{ 8: int x = Counter.read_count(),z = Counter.get_id(); 9: if(x%2==0) 10: out.println(x + " = even"); 11: else Stacktrace:
description The server encountered an internal error (Unable to compile class for JSP: An error occurred at line: 8 in the jsp file: /index.jsp The method get_id() is undefined for the type Counter 5: 6: <% 7: try{ 8: int x = Counter.read_count(),z = Counter.get_id(); 9: if(x%2==0) 10: out.println(x + " = even"); 11: else Stacktrace:) that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 8 in the jsp file: /index.jsp
The method get_id() is undefined for the type Counter
5:
6: <%
7: try{
8: int x = Counter.read_count(),z = Counter.get_id();
9: if(x%2==0)
10: out.println(x + " = even");
11: else
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:469)
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:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.29 logs.
Apache Tomcat/7.0.29
编辑:在重新启动计算机时问题消失了