struts2第十七讲学习笔记,Action处理复选框与JSP页面使用ognl处理map
来源:互联网 发布:淘宝云客服报名 编辑:程序博客网 时间:2024/05/21 20:38
1.Action处理复选框,可以使用数组和List 集合存放数据。
JSP代码
<body><form action="hobbies.action" method="post">
爱好:<input type="checkbox" name="hobbies" value="football" />足球 <input
type="checkbox" name="hobbies" value="basketball">篮球 <input
type="checkbox" name="hobbies" value="pingpangball">乒乓球 <input
type="checkbox" name="hobbies" value="yumaoball">羽毛球 <br>
喜欢:<input type="checkbox" name="hobby" value="football" />足 <input
type="checkbox" name="hobby" value="basketball">篮 <input
type="checkbox" name="hobby" value="pingpangball">乒乓 <input
type="checkbox" name="hobby" value="yumaoball">羽毛 <br>
<input type="submit" value="提交" />
</form>
</body>
Action中代码
public class hobby {private String[] hobby;
private List<String> hobbies;
public String execute() {
for (String h : hobby) {
System.out.print(" " + h);
}
System.out.println();
System.out.println(hobbies);//在控制台可以看到从前台接受到的数据
return null;
}
public List<String> getHobbies() {
return hobbies;
}
public void setHobbies(List<String> hobbies) {
this.hobbies = hobbies;
}
public String[] getHobby() {
return hobby;
}
public void setHobby(String[] hobby) {
this.hobby = hobby;
}
}
2.ognl表达式在页面中使用map的强大功能,懒得从数据库获取数据了,自己手写了一份。
Action代码
public String list() {map = getMap();//自己手动写的map
System.out.println(map);
list = service.getList();//从数据库拿到的list
System.out.println("list run:" + list);
return Action.SUCCESS;
}
public Map<Integer, String> getMap() {
Map<Integer,String> map = new HashMap<Integer,String>();
map.put(1, "黄铜会员");
map.put(2, "白银会员");
map.put(3, "黄金会员");
map.put(4, "钻石会员");
return map;
}
<s:iterator value="list" var="bean">
<tr>
<!--第二种写法,加入var=bean,从bean请求数据,带上#即可-->
<td><s:property value="#bean.id"/></td>
<td><s:property value="#bean.name"/></td>
<td><s:property value="#bean.password"/></td>
<td>
<!--每一个会员的等级都会显示出来,ognl表达式能直接拿到map对象而不声明-->
<s:property value="map[#bean.id]"/>
</td>
<td><a href="user/toUpdate.action?user.id=<s:property value="#bean.id"/>">修改</a></td>
</tr>
</s:iterator>
阅读全文
0 0
- struts2第十七讲学习笔记,Action处理复选框与JSP页面使用ognl处理map
- struts2第十二讲学习笔记,综合使用实现登录,页面中使用ognl表达式请求值
- struts2第十一讲笔记,在页面中使用ognl表达式
- JSP页面结合Struts2如何传递复选框对应的id数组到后台action中
- struts2系列学习笔记(6)---------------Action的结果处理
- Struts2学习笔记(七)——Action处理请求参数
- jsp查看页面是否被Action处理
- struts2 与 spring 使用aop处理Action异常
- struts2学习笔记----OGNL
- jsp复选框checkbox----表单处理
- struts2 ognl 取action类中的值到jsp页面中
- Struts2中jsp页面和Action类的数据交互之OGNL和值栈
- C#锐利体验 第十七讲 异常处理
- struts2学习笔记(1)---JSP页面向Action类传递参数
- struts2 action异常处理
- Struts2 action链式处理
- struts2 action处理ajax
- Struts2 Action处理
- 2017.6.4 入门组 NO.2——睡眠
- 整数排序 II
- 多线程Thread与Runnable 以及五种状态
- 动态网页
- 表单校验
- struts2第十七讲学习笔记,Action处理复选框与JSP页面使用ognl处理map
- HDU1401 Solitaire (bfs)
- 关于Linux的动态共享库的设置
- PNP: NetCat
- 【BZOJ】4774 修路 斯坦纳树
- 【LeetCode】517. Super Washing Machines
- Rectangles
- Android Volley的使用(一)基本网络请求
- maven 打包 web 项目时,war 包里的 class 不是最新的内容。