javaBean无法检测类属性

时间:2012-02-15 04:09:29

标签: java jsp javabeans

测试环境:netbeans7.11 + glassfish 3.11 这是jsp,类代码:

<%@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.

1 个答案:

答案 0 :(得分:2)

让您的getOperation()setOperation(...)方法公开

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

相关问题