簡體   English   中英

沒有屬性的getter方法-JSP異常

[英]No getter method for property - JSP Exception

在我的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>

在擴展ActionFormGetTareByBarcodeForm ,存在以下getter和setter方法,

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

tareWeightResult.jsp文件中,我以表格格式打印屬性TAREWEIGHT中的值。

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

在將其部署到weblogic服務器中后嘗試運行此功能時,日志中出現以下錯誤。

javax.servlet.jsp.JspException: No getter method for property barcodeString of bean result
at org.apache.struts.util.RequestUtils.lookup(RequestUtils.java:968)
at org.apache.struts.taglib.bean.WriteTag.doStartTag(WriteTag.java:286)
at jsp_servlet._jsp.__tareweightresult._jsp__tag2(__tareweightresult.java:237)
at jsp_servlet._jsp.__tareweightresult._jspService(__tareweightresult.java:174)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)

有人可以告訴我在這種情況下哪里出了問題嗎?

據我可以從你的代碼中看到,有沒有GetTareByBarcodeForm的情況下tareWeightList :后者包含String S,所以當bean:write嘗試提取屬性,它不能: String沒有這樣一個getter。

也許您應該重新訪問提取值的邏輯,並將結果包裝在適當的實例中。

因此,您的代碼應類似於以下內容:

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

那是更多的代碼,但從長遠來看會有所回報。

具有“結果”的id由TAREWEIGHT表示。 此對象是否具有barCodeString屬性? 在我看來,其中的Bean名稱存在問題

<bean:write>.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM