javax.servlet.jsp.JspException:没有属性的getter方法

问题描述 投票:1回答:3

我无法找出我做错了什么。我必然会在Form Bean中使用Form Bean,因为表单中有许多不同的部分。基本上,在同一表格上有一个响应部分和请求部分。

在初始化视图时,我得到一个没有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中:

<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页面:

<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:

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;
    }
}

子形态Bean:

public class GetAvailableAddressRequest implements Serializable{

    private String resellerId;

    public String getResellerID(){
        return this.resellerId;
    }
    public void setResellerID(String resellerId){
        this.resellerId = resellerId;
    }
}

行动类:

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;
}}
java struts struts-1
3个回答
3
投票

看来你的ressellerId字段的getter和setter在GetAvailableAddressRequest类中没有正确命名。您正在使用方法名称末尾的ID而不是下面的Id Corrected签名:

   public String getResellerId(){
        return this.resellerId;
    }
    public void setResellerId(String resellerId){
        this.resellerId = resellerId;
    }

0
投票

请记住,输入标记的属性名称必须与操作表单中的getter方法名称匹配

示例:在jsp中

<html:textarea property="productDescription" rows="15" cols="50" >
</html:textarea> 

在行动表格中

public String getProductDescription() {
    return productDescription;
}

0
投票

对于重定向到此处的其他人:首先检查所有变量/方法名称。

对我来说问题是Form Bean请求POJO类(带有getter和setter的类)的值以显示初始的jsp;因为它们没有价值,所以它们返回了一个空值,让jsp认为没有吸气剂。

只需设置默认值,即使是“”。

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;
}

这为我修好了!

© www.soinside.com 2019 - 2024. All rights reserved.