在Action中使用request接收Struts2传递的参数
2016-08-24 13:23
337 查看
//通过request接收网页传过来的参数
public String execute(){
//获得HttpServletRequest对象
HttpServletRequest request = (HttpServletRequest)ActionContext.getContext()
.get(org.apache.struts2.StrutsStatics.HTTP_REQUEST);
//获得name参数值
String name = request.getParameter("name");
BookDao bookDao = new BookDao();
//根据name参数值进行模糊查询
Map<String, Integer> booksMap = bookDao.getBooks(name);
//将查询结果放到request域中
request.setAttribute("result", booksMap);
return "result";
}
JSP位置提取相应对象代码:(此处为了方便,于是便在JAVA中写的,思路是一致的)
Map<String, Integer> result = (Map<String, Integer>) request.getAttribute("result");
for (Map.Entry<String, Integer> entry : result.entrySet()) {
System.out.println(entry.getKey()+"\t"+entry.getValue());
}
public String execute(){
//获得HttpServletRequest对象
HttpServletRequest request = (HttpServletRequest)ActionContext.getContext()
.get(org.apache.struts2.StrutsStatics.HTTP_REQUEST);
//获得name参数值
String name = request.getParameter("name");
BookDao bookDao = new BookDao();
//根据name参数值进行模糊查询
Map<String, Integer> booksMap = bookDao.getBooks(name);
//将查询结果放到request域中
request.setAttribute("result", booksMap);
return "result";
}
JSP位置提取相应对象代码:(此处为了方便,于是便在JAVA中写的,思路是一致的)
Map<String, Integer> result = (Map<String, Integer>) request.getAttribute("result");
for (Map.Entry<String, Integer> entry : result.entrySet()) {
System.out.println(entry.getKey()+"\t"+entry.getValue());
}
相关文章推荐
- struts2中的Action接收表单传递过来的参数有3种方法
- 关于在Struts2的Action中使用domain模型接收参数的问题
- jsp页面,使用Struts2标签,传递和获取Action类里的参数,注意事项。<s:a action><s:iterator><s:param>ognl表达式 在编写SSH2项目的时候,除
- struts2中的Action接收表单传递过来的参数有3种方法
- 道听途说Struts2之7:使用Action属性接收参数
- struts2中的Action接收表单传递的参数
- Struts2 使用annotation从action跳转到action并传递参数
- 关于在Struts2的Action中使用domain模型接收参数的问题
- Struts2中Action接收传递的参数
- Struts2 使用域模型给action传递参数以及DTO
- struts2中的Action接收表单传递过来参数的方式
- 关于在struts2中interceptor 中使用ActionInvocation 对象获得HttpServletRequest中封装的参数,以Map的形式
- struts2中的Action接收表单传递过来的参数
- 使用<a>标签调用struts2的action、传递动态参数、以及参数中出现加号等特殊字符的处理方法
- 关于在Struts2的Action中使用domain模型接收参数的问题
- Struts2_1000_CharacterEncoding 使用action属性接收参数,测试中文问题
- Struts2--action接收参数传递的四种方式
- Struts2使用action属性来接收参数
- 关于在Struts2的Action中使用domain模型接收参数的问题
- struts2中使用action属性传递参数