使用Logic:iterate标签后,页面能显示。但是数据没有,上一个帖子发了之后又一些收获。但是还是有错,今天修改了下。还有错:javax.servlet.jsp.JspException: Cannot find bean: "userlist" in scope: "request"代码如下:
ListUserActionForm的代码
public class ListUserActionForm extends ActionForm{
private String userid;
private String userpwd;
private int id;
/**
* @return the userid
*/
public String getUserid() {
return userid;
} /**
* @param userid the userid to set
*/
public void setUserid(String userid) {
this.userid = userid;
} /**
* @return the userpwd
*/
public String getUserpwd() {
return userpwd;
} /**
* @param userpwd the userpwd to set
*/
public void setUserpwd(String userpwd) {
this.userpwd = userpwd;
} /**
* @return the id
*/
public int getId() {
return id;
} /**
* @param id the id to set
*/
public void setId(int id) {
this.id = id;
} ListItemsAction的代码:
public ActionForward excute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws ClassNotFoundException, SQLException {
ListUserActionForm luf = (ListUserActionForm) form;
ArrayList userlist = new ArrayList();
String sql = "Select id,userid,userpwd from user";
Connection con = DBHelper.acquireConnection();
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
luf.setId(rs.getInt("id"));
luf.setUserid(rs.getString("userid"));
luf.setUserpwd(rs.getString("userpwd"));
userlist.add(luf);
}
System.out.println(userlist.size());
request.setAttribute("list", userlist);
return (mapping.findForward("success"));
}显示列表页面Admin.jsp的代码:
<table>
<tr>
<td>ID:</td>
<td>用户ID:</td>
<td>用户密码:</td>
</tr>
<tr>
<logic:notEmpty name="list">
<logic:iterate name="list" id="list">
<td><bean:write name="list" property="id" filter="true"/></td>
<td><bean:write name="list" property="userid" filter="true"/></td>
<td><bean:write name="list" property="userpwd" filter="true"/></td>
</logic:iterate>
</logic:notEmpty>
</tr>
</table>struts-config中的配置:
<action input="/Admin.jsp" name="listUserActionForm" path="/listItemsAction" scope="request" type="com.myapp.struts.Action.ListItemsAction">
<forward name="success" path="/listItemsAction"/>
</action>希望有人能帮我找到错误,跪谢。Struts标签Bean
ListUserActionForm的代码
public class ListUserActionForm extends ActionForm{
private String userid;
private String userpwd;
private int id;
/**
* @return the userid
*/
public String getUserid() {
return userid;
} /**
* @param userid the userid to set
*/
public void setUserid(String userid) {
this.userid = userid;
} /**
* @return the userpwd
*/
public String getUserpwd() {
return userpwd;
} /**
* @param userpwd the userpwd to set
*/
public void setUserpwd(String userpwd) {
this.userpwd = userpwd;
} /**
* @return the id
*/
public int getId() {
return id;
} /**
* @param id the id to set
*/
public void setId(int id) {
this.id = id;
} ListItemsAction的代码:
public ActionForward excute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws ClassNotFoundException, SQLException {
ListUserActionForm luf = (ListUserActionForm) form;
ArrayList userlist = new ArrayList();
String sql = "Select id,userid,userpwd from user";
Connection con = DBHelper.acquireConnection();
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
luf.setId(rs.getInt("id"));
luf.setUserid(rs.getString("userid"));
luf.setUserpwd(rs.getString("userpwd"));
userlist.add(luf);
}
System.out.println(userlist.size());
request.setAttribute("list", userlist);
return (mapping.findForward("success"));
}显示列表页面Admin.jsp的代码:
<table>
<tr>
<td>ID:</td>
<td>用户ID:</td>
<td>用户密码:</td>
</tr>
<tr>
<logic:notEmpty name="list">
<logic:iterate name="list" id="list">
<td><bean:write name="list" property="id" filter="true"/></td>
<td><bean:write name="list" property="userid" filter="true"/></td>
<td><bean:write name="list" property="userpwd" filter="true"/></td>
</logic:iterate>
</logic:notEmpty>
</tr>
</table>struts-config中的配置:
<action input="/Admin.jsp" name="listUserActionForm" path="/listItemsAction" scope="request" type="com.myapp.struts.Action.ListItemsAction">
<forward name="success" path="/listItemsAction"/>
</action>希望有人能帮我找到错误,跪谢。Struts标签Bean
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货