gpt4 book ai didi

javaBean 无法检测类属性

转载 作者:行者123 更新时间:2023-12-02 07:58:26 25 4
gpt4 key购买 nike

测试环境: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)

为什么检测不到操作?

将方法设置为公共(public)后

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.

最佳答案

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

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

关于javaBean 无法检测类属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9287756/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com