javax.servlet.jsp.JspException: 没有属性的 getter 方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16569377/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
javax.servlet.jsp.JspException: No getter method for property
提问by Srihari
I am unable to find out what I am doing wrong. I am bound to use Form Bean within Form Bean as there are numerous different parts of the form. Basically, there is a response part as well as request part on the same form.
我无法找出我做错了什么。我一定会在 Form Bean 中使用 Form Bean,因为表单有许多不同的部分。基本上,在同一个表单上有一个响应部分和请求部分。
While initializing the view, I am getting a no getter method exception.
I am using Struts 1.2
在初始化视图时,我收到了一个没有 getter 方法的异常。我在用Struts 1.2
javax.servlet.jsp.JspException: No getter method for property getAvailableAddres
sRequest.resellerId of bean org.apache.struts.taglib.html.BEAN
at org.apache.struts.util.RequestUtils.lookup(RequestUtils.java:968)
struts-config.xml:
struts-config.xml:
<form-beans>
<form-bean name="getAvailableAddress" type="com.wisor.talktalk.model.GetAvailableAddress" />
<form-bean name="provideRequest" type="com.wisor.talktalk.common.talktalkbean.RequestActionForm" />
</form-beans>
<action-mappings>
<action path="/ttTestJsp" type="com.wisor.talktalk.controller.TestJsp"
name="getAvailableAddress"
scope="session"
validate="false"
unknown="false">
<forward name="init" path="/WEB-INF/talk/preorderView/getAvailableAddress.jsp"/>
</action>
</action-mappings>
JSP Page:
JSP页面:
<html:form action="/ttTestJsp.do?task=getResponse" styleClass="form">
<fieldset>
<label class="inline label" for="reseller_id"><fmt:message
key="label.field.resellerId" />:</label>
<html:text
property="getAvailableAddressRequest.resellerId"
styleClass="mandatory" readonly="readonly"></html:text>
</fieldset>
<html:submit value="GetAddress"/>
</html:form>
FormBean Main:
FormBean 主要:
public class GetAvailableAddress extends ActionForm{
private GetAvailableAddressRequest getAvailableAddressRequest;
public void intilize(){
getAvailableAddressRequest = new GetAvailableAddressRequest();
}
public GetAvailableAddressRequest getGetAvailableAddressRequest(){
return this.getAvailableAddressRequest;
}
public void setGetAvailableAddressRequest(GetAvailableAddressRequest getAvailableAddressRequest){
this.getAvailableAddressRequest = getAvailableAddressRequest;
}
}
child Form Bean:
子窗体 Bean:
public class GetAvailableAddressRequest implements Serializable{
private String resellerId;
public String getResellerID(){
return this.resellerId;
}
public void setResellerID(String resellerId){
this.resellerId = resellerId;
}
}
Action Class:
动作类:
public class TestJsp extends Action {
Logger logger = Logger.getLogger(this.getClass());
@Override
public ActionForward execute( ActionMapping map, ActionForm actionForm,
HttpServletRequest request, HttpServletResponse response) throws Exception{
ActionForward forward = null;
GetAvailableAddress form = (GetAvailableAddress) actionForm;
form.intilize();
forward = map.findForward("init");
return forward;
}}
采纳答案by Juned Ahsan
It seems your getter and setter for ressellerId field are not properly named in GetAvailableAddressRequest class. You are using ID at the end of the method name instead of Id Corrected signatures below:
您的 ressellerId 字段的 getter 和 setter 似乎在 GetAvailableAddressRequest 类中没有正确命名。您在方法名称的末尾使用 ID 而不是下面的 Id 更正签名:
public String getResellerId(){
return this.resellerId;
}
public void setResellerId(String resellerId){
this.resellerId = resellerId;
}
回答by Frizz1977
Remember that the property name of the input tag must match with a getter method name in the action form
记住 input 标签的属性名必须与 action 表单中的 getter 方法名匹配
sample : in the jsp
示例:在jsp中
<html:textarea property="productDescription" rows="15" cols="50" >
</html:textarea>
in the action form
在行动形式
public String getProductDescription() {
return productDescription;
}
回答by Catalan Cabbage
To others being redirected here: first check all your variable/method names.
对于被重定向到这里的其他人:首先检查您所有的变量/方法名称。
The problem for me was that the Form Bean requested the values from the POJO class(the class with getters and setters) in order to display the initial jsp; since they had no value to begin with, they returned a null, making the jsp think there's no getter.
我的问题是 Form Bean 请求来自 POJO 类(具有 getter 和 setter 的类)的值以显示初始 jsp;因为它们一开始没有任何价值,所以它们返回了一个空值,使 jsp 认为没有 getter。
Just set a default value, even "".
只需设置一个默认值,甚至是“”。
public class GetAvailableAddressRequest implements Serializable{
//private String resellerId;
private String resellerId = "defaultValue";
public String getResellerID(){
return this.resellerId;
}
public void setResellerID(String resellerId){
this.resellerId = resellerId;
}
This fixed it for me!
这为我修好了!