(五)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 ...
随机推荐
- MAC常用快捷键 基本常用的都整理在这里了
写在前面Mac系统中有几个比较特殊的功能键,和Win系统的区别也主要在这里比如在Win系统中我们常用的Ctrl键,在Mac系统中对应的不是长得比较像的Cnotrol,而是Command键,貌似也是Ma ...
- WebService(axis2),整合springmvc
webservice:不同组织或者部门之间互通数据 https://www.cnblogs.com/buggou/p/8183738.html 1 package com.sh.test; 2 3 4 ...
- ubuntu12.04 64位安装opencv-2.4.9
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/dengshuai_super/artic ...
- osgGA::KeySwitchMatrixManipulator 跟随
#ifdef _WIN32 #include <Windows.h> #endif // _WIN32 #include <osg/Group> #include <os ...
- windows下打开binlog
上篇我们介绍了binlog(参见mysql的binlog),配置文件用的是linux下的my.cnf,那么在windows下如何打开binlog呢?道理是相同的,配置文件是不一样的.在windows下 ...
- Qwidget::update
void QWidget::update ()分析重绘事件激活 1看看手册中这段话 void QWidget::update () [slot] Updates the widget unless u ...
- form 提交页面不刷新实现
// no redirect <!DOCTYPE html> <html> <head> <meta http-equiv="Content-typ ...
- 【Leetcode_easy】680. Valid Palindrome II
problem 680. Valid Palindrome II solution: 不理解判断函数中的节点的问题... class Solution { public: bool validPali ...
- blender-编译源码
1. 获得源码,目前是以 2.8 版本为例子 https://www.blender.org/download/ 上,可以直接下面源码 2. 解压,在blender-2.80 目录下,运行 mak ...
- 【数据库开发】windows下使用c++调用redis
不废话,unix下c++调用 redis可以看这个: http://blog.csdn.net/youngqj/article/details/8266177 ==================== ...