0

我做错了什么?

我在 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

编辑:在重新启动计算机时问题消失了

4

2 回答 2

1

您已经解决了您的问题,但是这里有一些适当的选项可以让您的所有类和 JSP 文件重新加载或重新编译,这可能有助于理解您的情况:

刷新 Java 类- 确保在应用更改后重新编译您的类。另请参阅reloadableWeb 应用程序上下文的选项(默认为false)。

如果您希望 Catalina 监视 /WEB-INF/classes/ 和 /WEB-INF/lib 中的类的更改,请设置为 true,并在检测到更改时自动重新加载 Web 应用程序。


刷新 JSP 文件- 请参阅Tomcat Jasper 文档以获取有关development变量(默认为,true所以我猜这是您的情况下的值)和modificationTestInterval变量(默认为4 seconds)的详细信息,您可以使用该变量设置检查 JSP 文件的时间间隔必要时进行更改和编译。两者通常都设置在$CATALINA_BASE/conf/web.xml.

Jasper 是在开发模式下使用的吗?如果为 true,则可以通过 modifyTestInterval 参数指定检查 JSP 是否修改的频率。true 或 false,默认为 true。

于 2012-07-15T17:56:55.987 回答
0

I think its not problem with your code.I think your IDE is not building your project correctly ie .class file is not generated properly( or not generated). so try to compile this file manually and place generated .class file to appropriate folder of your project and then build and restart your server.Check on build its building new .JAR file or not

于 2012-07-16T06:08:02.883 回答