在<logic:iterate>内遍历hashmap取得的vo用<bean:write>输出属性的时候如下来写:<logic:iterate id="id" name="Form名字" property="hashmap名字">
...
<bean:write name="id" property="value.属性名"/>加的value即代表你从hashmap中取得的vo
...
<bean:write name="id" property="value.属性名"/>加的value即代表你从hashmap中取得的vo
解决方案 »
- 字符串操作
- js中 form表单的onsubmit有什么用?
- netbean安装visual web插件的问题
- 求助使用过滤器过滤:任意输入一个jsp地址,都能自动跳转到只有端口不同的该地址!解决结贴,在线等。。。
- struts2 服务器端验证国际化文件不起左右怎么办啊
- spring mvc +ext 整合 在不同机器上登陆,获取session 为同一个?
- FileUpload中的问题
- 急等啊,一个往ORACLE数据库的更新数据文件问题!!!!!!!!
- 关于使用spring validator from 中select 标签的问题
- java 数据解析的问题
- 怎样使加载jsp页面时候不提交表单就能调用strtus中的action
- tomcat异常停止
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
try {
UserForm user1=new UserForm();
user1.setUserid("a");
user1.setUsername("aaaa");
user1.setPassword("aaaa");
UserForm user2=new UserForm();
user2.setUserid("b");
user2.setUsername("bbbb");
user2.setPassword("bbbb");
UserForm user3=new UserForm();
user3.setUserid("c");
user3.setUsername("cccc");
user3.setPassword("cccc");
List<UserForm> list1 = new ArrayList<UserForm>();
List<UserForm> list2 = new ArrayList<UserForm>();
List<UserForm> list3 = new ArrayList<UserForm>();
list1.add(user1);
list2.add(user2);
list3.add(user3);
HashMap<String, List<UserForm>> map = new HashMap<String, List<UserForm>>();
map.put(user1.getUserid(),list1);
map.put(user2.getUserid(),list2);
map.put(user3.getUserid(),list3);
request.getSession().setAttribute("userAllMap", map);
return mapping.findForward("ok");
} catch (RuntimeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return mapping.findForward("fail");
}=========== jsp ===========
<table align="center">
<tr>
<td>学号</td>
<td>姓名</td>
<td>密码</td>
</tr>
<logic:iterate id="user" name="userAllMap">
<tr>
<logic:iterate name="user" property="value" id="userValue" >
<td>
<bean:write property="userid" name="userValue" />
</td>
<td>
<bean:write property="username" name="userValue" />
</td>
<td>
<bean:write property="password" name="userValue" />
</td>
</logic:iterate>
</tr>
</logic:iterate>
</table>struts 迭代输出 map 集合方法:1.map集合的 value 是 字符对象
String str ="str123";
HashMap<String, String> map = new HashMap<String, String>();
<logic:iterate id="str" name="map">
<bean:write name="str" property="key"/>//输出key
<bean:write name="str" property="value"/>//输出value
</logic:iterate>2.map集合的 value 是 集合
就点用嵌套迭代String[] a={"a" ,"ab","abc"};
String[] b={"1" ,"12","123","dfd"};
Strign[] c={"s"}
HashMap<String, String[]> map = new HashMap<String, String[]>();
map.put("a",a);
map.put("b",b);
map.put("c",c);
<logic:iterate id="strValue" name="map">
<bean:write name="strValue" property="key"/>>//输出key
/************* 对 value 进行迭代输出 **********/
<logic:iterate id="strValue" name="strValue" property="value">
<bean:write name="strValue" />//如果是集合装的是对象 就加上property 属性
</logic:iterate>
</logic:iterate>注意: hash.put(user1.userid,user1); 值是user对象 这是跌倒不出来的
会提示 Cannot create iterator for this collection 错误
以为logic:iterate 标签的 name 属性只能放 集合或字符对象 不能是实体对象
============================= 个人意见 ================================
如果没有特殊需求建议直接用list集合 不要要用map了
<logic:iterate id="user" name="userAllMap">
<tr>
<td>
<bean:write name="user" property="key"/>//键
</td>
<td>
<bean:write name="user" property="value.userid"/>
</td>
<td>
<bean:write name="user" property="value.username"/>
</td>
<td>
<bean:write name="user" property="value.password"/>
</td>
</tr>
</logic:iterate>