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. 对Zlib单元进行再封装

    对Zlib单元进行再封装 低版本DELPHI,如D7,ZLIB.pas单元封装的很简陋,因此有必要再封装,以增加使用的便利性. 高版本DELPHI,zlib.pas本身提供的接口已经相当完善. Zli ...

  2. JAVA SparkSQL初始和创建DataFrame的几种方式

    建议参考SparkSQL官方文档:http://spark.apache.org/docs/latest/sql-programming-guide.html 一.前述       1.SparkSQ ...

  3. sqlserver 动态sql执行execute和sp_executesql

    sp_executesql的运用 书写语法要点: exec sp_executesql @sql,N’参数1 类型1,参数2 类型2,参数3 类型3 OUTPUT’,参数1,参数2,参数3 OUTPU ...

  4. consul上删除已经注册的节点

    1,在consul上找到要删除的ID, 2,在consul的节点上删除这个ID:固定格式: 命令如果运行成功:没有任何的返回值 [root@beta-commonsrv01 ~] $curl --re ...

  5. [Java复习] 分布式事务 Part 1

    1. CAP理论 C: Consistency 一致性 A: Availability 可用性 P: Partition tolerance 分区容错性 CAP定理:一个分布式系统不可能同时满足CAP ...

  6. 不同三维引擎渲染IFC数据效果对比

  7. java 利用poi 实现excel合并单元格后出现边框有的消失的解决方法

    使用工具类RegionUtil CellRangeAddress cra = new CellRangeAddress(nowRowCount, nowRowCount + followSize-1, ...

  8. Django之model补充:一对多、跨表操作

    表结构概述 model.py : class Something(models.Model): name = models.CharField(max_length=32) class UserTyp ...

  9. vs2015配置link.exe环境变量

    https://www.cnblogs.com/johnwii/p/4966086.html

  10. 【Leetcode_easy】628. Maximum Product of Three Numbers

    problem 628. Maximum Product of Three Numbers 题意:三个数乘积的最大值: solution1: 如果全是负数,三个负数相乘还是负数,为了让负数最大,那么其 ...