Struts2笔记04 action获取表单数据
来源:互联网 发布:最优化方法应用例题 编辑:程序博客网 时间:2024/05/17 08:17
1.使用ActionContext
//1.获取ActionContext对象
ActionContext context = ActionContext.getContext();
//2.调用方法得到表单数据
//key是表单输入项name的属性值,value是输入的值
Map<String ,Object> map = context.getParameters();
Set<String> keys = map.keySet();
for(String key : keys ){
//根据key得到value
//数组形式,因为输入项可能是有复选框情况
Objectp[] obj = (Onject []) map.get(key);
System.out.println(Arrays.toString(obj));
}
2.使用ServletActionContext
//1.使用ServletActionContext获取request对象
HttpServletRequest request = ServletActionContext.getRequest();
//2.调用request里面的方法得到结果
String name = request.getParameter("name");
3.采用接口注入方式
public class TestAction3 extends ActionSupport implements ServletRequestAware {
private HttpServletRequest request = null;
public void setServletRequest(HttpServletRequest request) {
this.request = request;
}
@Override
public String execute() throws Exception {
String username = request.getParameter("username");
String password = request.getParameter("password");
String address = request.getParameter("address");
System.out.println(username + ":" + password + ":" + address);
return NONE;
}
private HttpServletRequest request = null;
public void setServletRequest(HttpServletRequest request) {
this.request = request;
}
@Override
public String execute() throws Exception {
String username = request.getParameter("username");
String password = request.getParameter("password");
String address = request.getParameter("address");
System.out.println(username + ":" + password + ":" + address);
return NONE;
}
阅读全文
0 0
- Struts2笔记04 action获取表单数据
- struts2 Action获取表单数据
- struts2 Action获取表单数据
- struts2 Action获取表单数据
- struts2 Action获取表单数据
- struts2 Action获取表单数据
- (转)struts2 Action获取表单数据
- Struts2 Action无法获取获取表单数据错误及解决方法
- Struts2 Action类无法获取web表单数据
- Struts2获取表单数据
- Action获取表单提交数据
- struts2 Action获取表单传值
- struts2 Action获取表单内容总结
- Struts2笔记06 封装获取表单数据方式
- Struts2框架自学之路——Action获取表单数据的方式以及表单数据的封装
- Struts2框架中action无法获取到jsp页面传递的表单数据的解决办法
- struts2学习(二)—action获取表单提交数据的三种方式
- 初学者易上手的SSH-struts2 02Action获取表单数据-通配符
- MongoDB安装及将MongoDB服务器作为windows服务运行
- get方法Required request body is missing
- int为空判断 -->Integer
- 利用颜色混合ccBlendFunc实现遮罩效果
- mkdir
- Struts2笔记04 action获取表单数据
- Zoj 3829 Known Notation
- 使用IntelliJ IDEA 配置Maven(入门)
- 微信支付退款接口
- python3/tensorflow1.2
- L1-027
- 面试题14—调整数组顺序使奇数位于偶数前面
- HTTPS抓包分析
- 5种方法解除开机密码