没有属性的getter方法 - JSP Exception

时间:2012-01-02 11:43:40

标签: java jsp struts javabeans

在我的Struts-config.xml文件中,

<action path="/getTareWeight" 
  type="com.astrazeneca.usbod.scale.actions.GetTareByBarcodeAction"  
  name ="getTareByBarcodeForm" 
  scope="request" 
  validate="true" 
  input="/jsp/getTareByBarcode.jsp">

    <forward name="success" path="/jsp/tareWeightResult.jsp" />
  </action>

在扩展GetTareByBarcodeForm的{​​{1}}中,以下是getter和setter方法,

ActionForm

public String getBarcodeString() { return (this.barcodeString); } public void setBarcodeString(String barcodeString) { this.barcodeString = barcodeString; } public String getResult() { return (this.result); } public void setResult(String result) { this.result = result; } 文件中,

GetTareByBarcodeAction.java

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{ String target = new String("success"); double tareWeight=0; String tw = new String(""); GetTareByBarcodeForm gForm = (GetTareByBarcodeForm)form; String errorString; StringTokenizer t = new StringTokenizer(gForm.getBarcodeString(), " \t\n\r\f:,;."); List barcodeList = new ArrayList(); List tareWeightList = new ArrayList(); while (t.hasMoreTokens()) { barcodeList.add(t.nextToken().trim()); } int size = barcodeList.size(); VesselProcessor vproc = VesselProcessor.getInstance(); for(int i=0;i<size;i++) { tareWeight = vproc.checkTares((String) barcodeList.get(i)); tw=Double.toString(tareWeight); tareWeightList.add(barcodeList.get(i)); tareWeightList.add(tw); String temp = barcodeList.get(i).toString(); gForm.setBarcodeString(temp); gForm.setResult(tw); } request.setAttribute("TAREWEIGHT", tareWeightList); return (mapping.findForward(target)); } 文件中,我以表格格式打印属性TAREWEIGHT中的值。

tareWeightResult.jsp

当我在weblogic服务器中部署它后尝试运行此功能时,我在日志中出现以下错误。

<logic:present name="TAREWEIGHT">
        <logic:iterate id="result" name="TAREWEIGHT">
            <tr>
                <td>
                    <bean:write name="result" property="barcodeString"/>
                </td>
                <td>
                    <bean:write name="result" property="result"/>
                </td>
            </tr>           
        </logic:iterate>
    </logic:present>

在这种情况下,有人能让我知道我哪里出错吗?

2 个答案:

答案 0 :(得分:1)

据我所知,您的代码中GetTareByBarcodeForm中没有tareWeightList个实例:后者包含String个,所以当bean:write尝试提取时属性,它不能:String没有这样的吸气剂。

也许您应该重新审视提取值的逻辑,并将结果包装在适当的实例中。

因此,您的代码应该更像以下内容:

    for (int i = 0; i < size; i++) {
        tareWeight = vproc.checkTares((String) barcodeList.get(i));
        tw = Double.toString(tareWeight);
        String temp = barcodeList.get(i).toString();

        GetTareByBarcodeForm f = new GetTareByBarcodeForm();
        f.setBarcodeString(temp);
        f.setResult(tw);
        tareWeightList.add(f);
    }

这样结果列表(即TAREWEIGHT传递的结果列表)将包含适当的对象。

但是,这不太好:现在,GetTareByBarcodeForm扮演两个角色,实际形式和搜索结果条目。所以我强烈建议引入一个新类TareTableEntry,并且只包含表格详细信息:

    for (int i = 0; i < size; i++) {
        tareWeight = vproc.checkTares((String) barcodeList.get(i));

        TareTableEntry entry = new TareTableEntry();
        entry.setBarcodeString(barcodeList.get(i));
        entry.setResult(tareWeight);
        tareWeightList.add(entry);
    }

这是更多的代码,但从长远来看,它会得到回报。

答案 1 :(得分:0)

带有“结果”的id由TAREWEIGHT表示。该对象是否具有barCodeString属性?在我看来,

中的bean名称存在一些问题
<bean:write>.