Map集合封装获取参数
16lz
2021-04-22
在struts2框架中接收参数的方式主要有属性驱动获取参数、对象驱动获取参数、模型驱动获取参数以及集合封装获取参数这四种,而集合封装获取参数主要是有List集合、Map集合这两种方式的,集合封装获取参数操作方式较为简便,本章节主要学习的是Map集合封装获取参数的操作方式,详细如下;
Map集合封装获取参数
- 1、Map集合封装获取参数
- 第一步:创建Action类
- 第二步:Jsp表单
- 第三步:Struts.xml文件配置
- 第四步:Demo测试
- 《END》
1、Map集合封装获取参数
第一步:创建Action类
代码:
// struts2使用集合类型封装获得参数 --- List、Mappublic class DemoApi7 extends ActionSupport {// map集合封装获取参数创建一个map集合对象;private Map<String, String> map;public String action_name() throws Exception {System.out.println("map:"+map);return SUCCESS;}public Map<String, String> getMap() {return map;}public void setMap(Map<String, String> map) {this.map = map;}}
第二步:Jsp表单
代码:
<form action="${pageContext.request.contextPath}/api/DemoApi7" method="post"><label>map1:<input type="text" name="map['map集合1']" ></label><br/><label>map2:<input type="text" name="map['map集合2']" ></label><br/><input type="submit" value="OK"></form>
在map集合封装获取参数的jsp表单中input标签的name属性值有些特殊,需要传给相应map属性并指定传给此map属性中的哪个键。
第三步:Struts.xml文件配置
代码:
<!-- Map集合封装获取参数 --> <action name="DemoApi7" class="com.java.Demo.api.DemoApi7" method="action_name"> <result name="success" type="dispatcher">/form4.jsp</result> </action>
第四步:Demo测试
参数输入:
控制台输出:
成功~
struts2中几种参数传递获取方式如下:
属性驱动方式获得参数:https://blog.csdn.net/qq_40762011/article/details/84975163
对象驱动方式获得参数:https://blog.csdn.net/qq_40762011/article/details/84975677
模型驱动方式获得参数:https://blog.csdn.net/qq_40762011/article/details/84976004
List集合封装传递获取参数:https://blog.csdn.net/qq_40762011/article/details/84976453
Map集合封装传递获取参数:https://blog.csdn.net/qq_40762011/article/details/84988210
《END》
©著作权归作者所有:来自51CTO博客作者天明不是能的原创作品,如需转载,请注明出处,否则将追究法律责任更多相关文章
- 电商快递物流的电子面单打印接口API案例代码
- 电商快递物流电子面单图片接口API案例代码
- 快递物流接口API如何获取第三方电商平台账号授权案例
- List集合封装获取参数
- shell编程及自动化运维----变量
- 谁要是敢用Map传参数,我喵喵就打死他
- 怎么在java中创建一个自定义的collector
- java 8 stream reduce详解和误区
- 初学Redis最清晰完整的教程