参考:The tag then loops over each member of the collection (which can either be an array, a Collection, Enumeration, Iterator, or Map), setting the id to the element and evaluating its contents.
1) session.setAttribute("list", list);在jsp的<html:form>对应的action中设置.在action的execute里设置session.setAttribute("list", list);?是的,在request中得到getSession,然后再session.setAttribute("list", list);2) 2>一般情况下</logic:iterate>提交到actionForm到Action的?我更不明白了,请问下,如果你想在一个独立的页面里显示新闻列表,该怎么做?不能直接请求news.jsp吗? 难道还要为这个页面写一个action?如果你的<logic:iterate>只是用来作结果输出的话,那么forward 到这个页面来就应该可以了。请参考: The iterate tag is probably the most complicated one in the logic tag library, but also one of the most useful. At its heart, it's pretty simple. You specify a collection with the name or name and property attribute, and specify a bean to hold the individual members of the collection in id. The tag then loops over each member of the collection (which can either be an array, a Collection, Enumeration, Iterator, or Map), setting the id to the element and evaluating its contents.主要是:You specify a collection ,property attribute,and specify a bean 以上三个是必须的,如果你的</logic:iterate>需要提交处理,但如果不处理就没有必要了。愚见,呵呵,仅供参考!!!
The iterate tag is probably the most complicated one in the logic tag library, but also one of the most useful. At its heart, it's pretty simple. You specify a collection with the name or name and property attribute, and specify a bean to hold the individual members of the collection in id. The tag then loops over each member of the collection (which can either be an array, a Collection, Enumeration, Iterator, or Map), setting the id to the element and evaluating its contents.主要是:You specify a collection ,property attribute,and specify a bean
以上三个是必须的,如果你的</logic:iterate>需要提交处理,但如果不处理就没有必要了。愚见,呵呵,仅供参考!!!
哦,原来这样,谢谢studyday(好好学习天天向上) 如果我不是做结果输出,而是事先在前台jsp页面显示数据用什么标签?
也就是用不到action的页面,该怎么办?
<bean:write name="fruit" />
</logic:iterate>fruito 为一个集合.
<html:form action="/aa/bb" method="post">
aa/bb和你转发的action对应,在xml通过<action path="aa/bb" name="ListForm"../>
及ListForm对应的你的ActionForm(aaForm extends ActionForm)
<logic:iterate id="userList" name="aaForm" type="aa.bb.cc.aaForm">
<tr>
<td><bean:write name="userList" property="username"/></td>
<td><bean:write name="userList" property="password"/></td>
<td><bean:write name="userList" property="email"/></td>
</tr>
</logic:iterate>name,type property都注意大小写了,看你的get set 怎么写了
如果Action ActionForm <html:form 这些没对应上,大小写没对,挂的我也没办法了:>
<logic:iterate id="userList" name="aaForm" type="aa.bb.cc.aaForm">
aaForm与aaForm extends ActionForm名字对应?还是与Action对应?我都搞胡了,不是在Action的execute方法里执行session.setAttribute("list", list);吗?谢谢两位
<logic:iterate id="userList" name="list" type="oa.hibernate.po.User" scope="request">
<tr>
<td><bean:write name="userList" property="username"/></td>
<td><bean:write name="userList" property="password"/></td>
<td><bean:write name="userList" property="email"/></td>
</tr>
</logic:iterate>userList是你在action里面定义的ActionForm
list是你从Action里面所存从库里面查出来的记录.一个ArrayList
如上面.
userList.setUsername(rs.getString("name"));
list.add(userList);
excute方法里面:
reqeust.setAttribute("list", list);
在jsp页面上如你所列出来的就可以调用了.
<form-beans>
<form-bean name="nameForm" type="com.my.StForm"/>
</form-beans> <action-mappings>
<action path="/aa/bb"
type="com.my.StAction"
name="nameForm"
scope="request"
parameter="operate"
unknown="false"
validate="false">
<forward name="success" path="aa"/>
</action>
</action-mappings>
</struts-config><html:form action="/aa/bb" method="post"><logic:iterate id="userList" name="StForm" type="com.my.StForm">
<tr>
<td><bean:write name="userList" property="username"/></td>
<td><bean:write name="userList" property="password"/></td>
<td><bean:write name="userList" property="email"/></td>
</tr>
</logic:iterate>
</html:form>
1、为了不在JSP中带许多《% %》,所以用户的请求还是发给Action处理;
2、在Action中用getSimpleProperty函数读取数据,例如:
String username = (String) PropertyUtils.getSimpleProperty(form, USERNAME);
String password = (String) PropertyUtils.getSimpleProperty(form, PASSWORD);
把数据收集到list中,再用reqeust.setAttribute("list",list);保存数据。