(五)springmvc之获取表单提交的数据
8.1:使用Request
<form method="post" id="form1" action="<%=request.getContextPath()%>/formData/formData_1">
<input type="text" name="username" value="用户名"/>
<input type="checkbox" name="check_1" value="复选框1"/>复选框1
<input type="checkbox" name="check_1" value="复选框2"/>复选框2
<input type="checkbox" name="check_1" value="复选框3"/>复选框3
<input type="submit" value="提交"/>
</form> 8.2:使用形参注解
<form method="post" id="form1" action="<%=request.getContextPath()%>/formData/formData_2">
<input type="text" name="username" value="用户名"/>
<input type="checkbox" name="check_1" value="复选框1"/>复选框1
<input type="checkbox" name="check_1" value="复选框2"/>复选框2
<input type="checkbox" name="check_1" value="复选框3"/>复选框3
<input type="submit" value="提交"/>
</form>
8.3:使用对象来获取
<form method="post" id="form1" action="<%=request.getContextPath()%>/formData/formData_3">
<input type="text" name="username" value="用户名"/>
<input type="checkbox" name="check_1" value="复选框1"/>复选框1
<input type="checkbox" name="check_1" value="复选框2"/>复选框2
<input type="checkbox" name="check_1" value="复选框3"/>复选框3
<input type="submit" value="提交"/>
</form>
controller
package com.controller.formdata; import java.util.Arrays; import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView; import com.bean.UserBean; @Controller
@RequestMapping(value = "/formData")
public class FormData {
@Autowired
private HttpServletRequest request;
@Autowired
private HttpServletResponse response;
@Autowired
private HttpSession session;
@Autowired
private ServletContext servletContext; @RequestMapping(value = "/formData_1")
public ModelAndView formData_1() throws Exception {
this.request.setCharacterEncoding("UTF-8");
String username = request.getParameter("username");
String[] check_1 = request.getParameterValues("check_1"); System.out.println(username);
System.out.println(Arrays.asList(check_1)); return null;
} @RequestMapping(value = "/formData_2")
public ModelAndView formData_2(
@RequestParam(name = "username") String username_2, String[] check_1)
throws Exception {
System.out.println("formData_2方法");
System.out.println(username_2);
System.out.println(Arrays.asList(check_1)); return null;
} /**
* 类似Struts中的模型驱动
*
* @param userBean
* @return
* @throws Exception
*/
@RequestMapping(value = "/formData_3")
public ModelAndView formData_3(UserBean userBean) throws Exception {
System.out.println("formData_3方法");
System.out.println(userBean.getUsername());
System.out.println(Arrays.asList(userBean.getCheck_1())); return null;
} }
UserBean.java
public class UserBean implements Serializable {
private String username;
private String[] check_1;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String[] getCheck_1() {
return check_1;
}
public void setCheck_1(String[] check_1) {
this.check_1 = check_1;
}
}
(五)springmvc之获取表单提交的数据的更多相关文章
- springmvc后台获取表单提交的数据——@ModelAttribute等方式
1.通过注解ModelAttribute直接映射表单中的参数到POJO.在from中的action写提交的路径,在input的name写参数的名称. package com.demo.model; p ...
- koa 基础(十一)koa 中 koa-bodyparser 中间件获取表单提交的数据
1.app.js /** * koa 中 koa-bodyparser 中间件获取表单提交的数据 * 1.npm install --save koa-bodyparser * 2.引入 const ...
- koa 基础(十)原生node.js 在 koa 中获取表单提交的数据
1.app.js // 引入模块 const Koa = require('koa'); const router = require('koa-router')(); /*引入是实例化路由 推荐*/ ...
- 获取表单提交的数据getParameter()方法
请求对象:request public String getParameter(String name); 通过request的getParameter(String name)方法获取 表单里面的n ...
- 在html中如何获取表单提交的数据
a.html: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www ...
- springMVC+thymeleaf form表单提交前后台数据传递
后端: @RequestMapping(value = "/add", method=RequestMethod.POST) public String save(@ModelAt ...
- 第6章—渲染web视图—SpringMVC+Thymeleaf 处理表单提交
SpringMVC+Thymeleaf 处理表单提交 thymleaf处理表单提交的方式和jsp有些类似,也有点不同之处,这里操作一个小Demo,并说明: 1.demo的结构图如下所示: pom.xm ...
- 在Action中获取表单提交数据
-----------------siwuxie095 在 Action 中获取表单提交数据 1.之前的 Web 阶段是提交表单到 Servlet,在其中使用 Request 对象 的方法获取数据 2 ...
- Struts2_day02--Action获取表单提交数据
Action获取表单提交数据 1 之前web阶段,提交表单到servlet里面,在servlet里面使用request对象里面的方法获取,getParameter,getParameterMap 2 ...
随机推荐
- 近似最近邻算法-annoy解析
转自https://www.cnblogs.com/futurehau/p/6524396.html Annoy是高维空间求近似最近邻的一个开源库. Annoy构建一棵二叉树,查询时间为O(logn) ...
- ArcGIS后台地理处理(64 位)
注: 后台地理处理(64 位) 可用作 ArcGIS 10.1 for Desktop.Service Pack 1 及更高版本上的独立安装.只有在已安装 后台地理处理(64 位) 产品的情况下,以下 ...
- GDPR全文翻译(一)
General Data Protection Regulation <一般数据保护法案>全文翻译(一) 编者按 2016年4月14日,欧洲议会投票通过了商讨四年的<一般数据保护法案 ...
- vue项目中 favicon.ico不能正确显示的问题
方法一:修改index.html文件 <link rel="shortcut icon" type="image/x-icon" href="f ...
- 阶段5 3.微服务项目【学成在线】_day07 课程管理实战_03-新增课程-课程分类查询
2 新增课程 2.1 需求分析 用户操作流程如下: 1.用户进入“我的课程”页面,点击“新增课程”,进入新增课程页面 2.填写课程信息,选择课程分类.课程等级.学习模式等. 3.信息填写完毕,点击“提 ...
- 请求头User-Agent作用?
请求头User-Agent作用 答: User Agent中文名为用户代理,是Http协议中的一部分,属于头域的组成部分,User Agent也简称UA.它是一个特殊字符串头,是一种向访问网站提供你所 ...
- python之json处理
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它基于JavaScript(Standard ECMA-262 3rd Edition - Decembe ...
- es6 关于map和for of的区别有哪些?
1.es6 关于map和for of的区别有哪些? ——主要想了解一下性能方面的
- python:python2与python3共存时,pip冲突,提示Fatal error in launcher: Unable to create process using '"d:\python27\python2.exe" "D:\Python27\Scripts\pip2.exe" '
问题背景: 机器上同时装了python2.和python3后,导致只能用pip3了,使用pip2时提示:Fatal error in launcher: Unable to create proces ...
- CEIWEI USBMonitor监控驱动 OCX/SDK USB 监控精灵 USB过滤驱动
CEIWEI USBMonitor监控精灵软件SDK USBMonitorX.dll SDK,能够嵌入到你的App程序中,从而在你的App中实现USB端口协议分析.调试USB设备的协议信息,并可以拦截 ...