2012-02-15 68 views
0

测试环境:netbeans7.11 + GlassFish的3.11 这里是JSP,类代码:的javaBean不能检测类属性

<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<jsp:useBean id="gb" class="GameBean" scope="session" /> 
<jsp:setProperty name="gb" property="operation" value="OOOOOOOOO" /> 
<!DOCTYPE html> 
<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
     <title>JSP Page</title> 
    </head> 
    <body> 
     <h1><jsp:getProperty name="gb" property="operation" /></h1> 
    </body> 
</html> 



public class GameBean { 
    private String operation; //operation 

    public void setOperation (String operation) { 
     this.operation = operation; 
    } 

    public String getOperation() { 
     return this.operation; 
    } 

} 


Error message: org.apache.jasper.JasperException: PWC6054: Cannot find any information on property 'operation' in a bean of type 'GameBean' 
C:\Users\ray\Desktop\OU\COMPS311\tma02\web\nbproject\build-impl.xml:612: Java returned: 1 BUILD FAILED (total time: 1 second) 

为什么不能检测操作?

设置方法公开

Compiling 1 source file to C:\Users\test\web\build\generated\classes 
C:\Users\test\web\build\generated\src\org\apache\jsp\GameBean_jsp.java:47: error: cannot find symbol 
     GameBean GameBean = null; 
    ^
    symbol: class GameBean 
    location: class GameBean_jsp 
C:\Users\test\web\build\generated\src\org\apache\jsp\GameBean_jsp.java:49: error: cannot find symbol 
     GameBean = (GameBean) _jspx_page_context.getAttribute("GameBean", PageContext.SESSION_SCOPE); 
    symbol: class GameBean 
    location: class GameBean_jsp 
C:\Users\test\web\build\generated\src\org\apache\jsp\GameBean_jsp.java:51: error: cannot find symbol 
      GameBean = new GameBean(); 
    symbol: class GameBean 
    location: class GameBean_jsp 
C:\Users\test\web\build\generated\src\org\apache\jsp\GameBean_jsp.java:66: error: cannot find symbol 
     out.write(org.apache.jasper.runtime.JspRuntimeLibrary.toString((((GameBean)_jspx_page_context.findAttribute("GameBean")).getOperation()))); 
    symbol: class GameBean 
    location: class GameBean_jsp 
4 errors 
C:\Users\test\web\nbproject\build-impl.xml:629: The following error occurred while executing this line: 
C:\Users\test\web\nbproject\build-impl.xml:263: Compile failed; see the compiler error output for details. 

回答

2

让您getOperation()setOperation(...)方法公共后。

更新后,新问题似乎是您的GameBean在您未导入JSP的某个包中定义(或使用完全限定名称)。

+0

但没有包已定义 – hkguile 2012-02-15 04:58:37

+0

@hkinterview这里http://www.javafixer.org/cannot-find-symbol.php是你得到的错误的解释。我建议你阅读它,看看问题出在哪里。 – 2012-02-15 05:03:41

+0

问题得到解决,谢谢 – hkguile 2012-02-15 05:11:33