我之前使用scriptlets,但現在我切換到了mvc。我不能夠檢索到JSP頁面,並得到錯誤的值:javax.el.PropertyNotFoundException:在類型java.lang.String上找不到屬性'tname'
javax.el.PropertyNotFoundException: Property 'tname' not found on type java.lang.String
代碼的Bean:
public class regForm extends org.apache.struts.validator.ValidatorForm implements Iprafunctions {
private String tname = null;
private String tfee = null;
public String getTfee() {
return tfee;
}
public void setTfee(String tfee) {
this.tfee = tfee;
}
public String getTname() {
return tname;
}
public void setTname(String tname) {
this.tname = tname;
}
public regForm() {
super();
}
}
動作控制器:
public ActionForward mvc(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
regForm reg = (regForm) form;
String sql = "Select tname,tfee from addtest order by tname";
ResultSet rs = SQLC.getData(sql, null);
Collection myBeans = new ArrayList();
while (rs.next()) {
String testname = rs.getString("tname");
String testfee = rs.getString("tfee");
reg.setTname(testname);
reg.setTfee(testfee);
myBeans.add(reg.getTname());
myBeans.add(reg.getTfee());
}
request.setAttribute("myBeans", myBeans);
return mapping.findForward(SUCCESS);
}
在JSP頁面
訪問<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<table>
<tr><td>Name</td><td>Fee</td></tr>
<c:forEach var="reg" items="${myBeans}">
<tr>
<td><c:out value="${reg.tname}"></c:out></td>
<td><c:out value="${reg.tfee}"></c:out></td>
</tr>
</c:forEach>
</table>
我有一個快速的問題,我還沒有和支柱的工作,但你應該不是屬性添加到響應。我看到你在請求中添加它。 – raddykrish
@raddy沒有,屬性被設置爲請求進行內部通信,然後請求只是轉發 –
謝謝@JigarJoshi因爲.. – raddykrish