[英]No getter method for property - JSP Exception
In my Struts-config.xml
file, 在我的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>
In GetTareByBarcodeForm
which extends the ActionForm
the following getter and setter methods are there, 在扩展ActionForm
的GetTareByBarcodeForm
,存在以下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;
}
In the GetTareByBarcodeAction.java
file, 在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));
}
In the tareWeightResult.jsp
file, i am printing the values in the attribute TAREWEIGHT in a table format. 在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>
When I tried to run this functionality after deploying it in weblogic server, I have the below error in log. 在将其部署到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)
Can anybody let me know where I have gone wrong in this scenario? 有人可以告诉我在这种情况下哪里出了问题吗?
As far as I can see from your code, there are no GetTareByBarcodeForm
instances in the tareWeightList
: the latter contains String
s, so when bean:write
tries to extract the property, it cannot: String
doesn't have such a getter. 据我可以从你的代码中看到,有没有GetTareByBarcodeForm
的情况下tareWeightList
:后者包含String
S,所以当bean:write
尝试提取属性,它不能: String
没有这样一个getter。
Perhaps you should revisit your logic extracting the values, and wrap the results in proper instances. 也许您应该重新访问提取值的逻辑,并将结果包装在适当的实例中。
So your code should look more like the following: 因此,您的代码应类似于以下内容:
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);
}
so that the result list, the one you pass as TAREWEIGHT
, would contain proper objects. 这样您作为TAREWEIGHT
传递的结果列表将包含适当的对象。
Still, that's not too good: now, GetTareByBarcodeForm
plays two roles, the actual form and the search result entry. 不过,这还不太好:现在, GetTareByBarcodeForm
扮演两个角色,即实际表单和搜索结果条目。 So I would highly recommend introducing a new class, TareTableEntry
, and only include table details in it: 因此,我强烈建议您引入一个新类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);
}
That's more code, but it pays off in a long run. 那是更多的代码,但从长远来看会有所回报。
The id with "result" is represented by TAREWEIGHT. 具有“结果”的id由TAREWEIGHT表示。 Does this object has the barCodeString property ? 此对象是否具有barCodeString属性? It looks to me that there is some problem with the bean name in 在我看来,其中的Bean名称存在问题
<bean:write>.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.