2012-02-15 65 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