struts2第十七讲学习笔记,Action处理复选框与JSP页面使用ognl处理map
2017-06-05 19:36
519 查看
1.Action处理复选框,可以使用数组和List 集合存放数据。
JSP代码
Action中代码
2.ognl表达式在页面中使用map的强大功能,懒得从数据库获取数据了,自己手写了一份。
Action代码
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> |
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; } } |
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> |
相关文章推荐
- Struts2学习笔记之struts.xml配置常量和Action处理流程
- 【学习笔记】Struts2之一个Action包含多个控制处理逻辑
- struts学习笔记:在jsp页面显示结果的三种方式
- 在jsp页面使用ognl无法取到值(Struts,Spring,Hibernate)
- jsp页面,使用Struts2标签,传递和获取Action类里的参数,注意事项。<s:a action><s:iterator><s:param>ognl表达式 在编写SSH2项目的时候,除
- Struts2学习笔记之struts.xml配置常量和Action处理流程
- 【Struts2学习笔记】struts2.5使用通配符配置action跳转
- PHP学习笔记——使用回调函数处理数组函数array_map()
- SpringMVC学习笔记(四)使用JSP处理表单(处理用户注册表单)
- 在Action中查询出SQL SERVER表的数据,返回一个list。怎么在JSP页面中使用Struts标签,显示出表中的内容?(转)
- JSP学习笔记(五):日期处理、页面重定向、点击量统计、自动刷新和发送邮件
- struts:将Action处理后的数据传递给前台jsp页面
- JSP学习笔记(三)-----使用JSP处理用户注册和登陆
- [学习笔记]jsp中超级链接 中文编码处理
- MonoRail学习笔记八:页面缓存的使用
- JSP学习笔记——过滤器(二)使用
- JSP学习笔记(四)-----JSP动作的使用
- JSP学习笔记(五)-----JSP中使用JavaBean
- Servlet学习笔记(四)-----使用Servlet处理用户注册和登陆
- Struts 1 学习笔记-2-1(Struts标签的使用步骤)