gpt4 book ai didi

java - 属性没有 getter 方法 - JSP 异常

转载 作者:行者123 更新时间:2023-12-01 15:37:10 24 4
gpt4 key购买 nike

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

有人可以告诉我在这种情况下我哪里出了问题吗?

最佳答案

据我从您的代码中看到,tareWeightList 中没有 GetTareByBarcodeForm 实例:后者包含 String,因此当 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);
}

虽然代码较多,但从长远来看是有返回的。

关于java - 属性没有 getter 方法 - JSP 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8700391/

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