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之获取表单提交的数据的更多相关文章

  1. springmvc后台获取表单提交的数据——@ModelAttribute等方式

    1.通过注解ModelAttribute直接映射表单中的参数到POJO.在from中的action写提交的路径,在input的name写参数的名称. package com.demo.model; p ...

  2. koa 基础(十一)koa 中 koa-bodyparser 中间件获取表单提交的数据

    1.app.js /** * koa 中 koa-bodyparser 中间件获取表单提交的数据 * 1.npm install --save koa-bodyparser * 2.引入 const ...

  3. koa 基础(十)原生node.js 在 koa 中获取表单提交的数据

    1.app.js // 引入模块 const Koa = require('koa'); const router = require('koa-router')(); /*引入是实例化路由 推荐*/ ...

  4. 获取表单提交的数据getParameter()方法

    请求对象:request public String getParameter(String name); 通过request的getParameter(String name)方法获取 表单里面的n ...

  5. 在html中如何获取表单提交的数据

    a.html: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www ...

  6. springMVC+thymeleaf form表单提交前后台数据传递

    后端: @RequestMapping(value = "/add", method=RequestMethod.POST) public String save(@ModelAt ...

  7. 第6章—渲染web视图—SpringMVC+Thymeleaf 处理表单提交

    SpringMVC+Thymeleaf 处理表单提交 thymleaf处理表单提交的方式和jsp有些类似,也有点不同之处,这里操作一个小Demo,并说明: 1.demo的结构图如下所示: pom.xm ...

  8. 在Action中获取表单提交数据

    -----------------siwuxie095 在 Action 中获取表单提交数据 1.之前的 Web 阶段是提交表单到 Servlet,在其中使用 Request 对象 的方法获取数据 2 ...

  9. Struts2_day02--Action获取表单提交数据

    Action获取表单提交数据 1 之前web阶段,提交表单到servlet里面,在servlet里面使用request对象里面的方法获取,getParameter,getParameterMap 2 ...

随机推荐

  1. 构建Hadoop监控共同体

    HDFS监控背后那些事儿,构建Hadoop监控共同体 原创: 应用研发部 京东云 2018-12-19 https://mp.weixin.qq.com/s/kulwDgwu-rYf4SvQ1dOwc ...

  2. vue开发环境、正式环境的配置及原理

    修改prod.env.js里的内容,修改后的内容如下: 'use strict' module.exports = { NODE_ENV: '"production"', EVN_ ...

  3. VSCode 代码格式化 快捷键

    Visual Studio Code可以通过以下快捷键 格式化代码: On Windows  Shift + Alt + F On Mac  Shift + Option + F On Ubuntu ...

  4. LC 456. 132 Pattern

    Given a sequence of n integers a1, a2, ..., an, a 132 pattern is a subsequence ai, aj, ak such that  ...

  5. Java面试之http知识点(必问)

    Java面试之http知识点(必问)   版权声明:本文为博主原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/q ...

  6. [Java复习] 分布式锁 Zookeeper Redis

    一般实现分布式锁都有哪些方式? 使用 Redis 如何设计分布式锁?使用 Zookeeper 来设计分布式锁可以吗? 这两种分布式锁的实现方式哪种效率比较高? 1. Zookeeper 都有哪些使用场 ...

  7. 初始化jsp页面下拉选备选项【我】

    将下列 script标签放到页面的最下端 <!-- 初始化的全局变量,供js中使用,主要拼接下拉选的初始化值 --> <script type="text/javascri ...

  8. ElasticSearch的Gateway及存储原理

    ES里有一个叫做gateway的东西,今天抽空理一下,前面翻译ES的一篇博文叫做“搜索引擎与时间机器”,既然里面谈到了时间机器,就免不了需要穿越时空的的门咯,I guess,也许gateway这名字就 ...

  9. No WebApplicationContext found: no ContextLoaderListener registered

    修改前运行报错:No WebApplicationContext found: no ContextLoaderListener registered? <web-app> <dis ...

  10. 利用 AWS 无服务架构之语音合成

    目录 一.架构图 二.服务部署 2.1.创建 DynamoDB 表 2.2.创建 S3 2.2.1 静态网页存储桶 2.2.2.音频存储桶 2.3.创建 SNS Topic 2.4.为 Lambda ...