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. qt 设置程序居中

    widget *s =new widget; , ); s->show();

  2. 安卓APP在线升级

    安卓APP在线升级 通过IDHTTP组件在线下载APP到手机中,然后自动安装这个APP程序. 1)在线下载APP程序 需引用单元: {$IFDEF ANDROID} FMX.Helpers.Andro ...

  3. Android绘图通用第三方控件

      https://github.com/ddanny/achartengine     CodePull requests 2SecurityInsights Charting library fo ...

  4. IDEA新建本地项目关联远程git仓库

    现在远程git仓库创建一个repository,然后本地创建项目,最后进行关联.三板斧,打完收工. 第一步.第二步地球人都知道,略过不表,第三步比较关键,举个例子: 0.创建本地Git仓库:VCS - ...

  5. trylock方法

    synchronized 是不占用到手不罢休的,会一直试图占用下去. 与 synchronized 的钻牛角尖不一样,Lock接口还提供了一个trylock方法.trylock会在指定时间范围内试图占 ...

  6. PAT 甲级 1045 Favorite Color Stripe (30 分)(思维dp,最长有序子序列)

    1045 Favorite Color Stripe (30 分)   Eva is trying to make her own color stripe out of a given one. S ...

  7. Spring Boot使用过滤器Filter

    首先创建一个测试用的controller:TestController: package com.zifeiy.test.controller; import org.springframework. ...

  8. 【Leetcode_easy】796. Rotate String

    problem 796. Rotate String solution1: class Solution { public: bool rotateString(string A, string B) ...

  9. 【web 安全测试思路】图形验证码对服务器的影响

    前言 图片验证码是为了防止恶意破解密码.刷票.论坛灌水等才出现的,但是你有没有想过,你的图形验证码竟然可能导致服务器的崩溃? 利用过程 这里以phpcms为例,首先需要找一个图形验证码. 将图片拖动到 ...

  10. 整理Vue.js 面试题

    Vue.js 面试题整理   Vue项目结构介绍 build 文件夹:用于存放 webpack 相关配置和脚本. config 文件夹:主要存放配置文件,比如配置开发环境的端口号.开启热加载或开启gz ...