博客
关于我
SpringMVC基础-04-单个接受表单提交数据
阅读量:552 次
发布时间:2019-03-09

本文共 3009 字,大约阅读时间需要 10 分钟。

pom.xml

4.0.0
com.monkey1024
02mvc
0.0.1-SNAPSHOT
war
junit
junit
3.8.1
test
javax.servlet
javax.servlet-api
3.1.0
org.springframework
spring-webmvc
5.0.4.RELEASE
02mvc
org.apache.maven.plugins
maven-compiler-plugin
1.8
1.8
UTF-8

web.xml

characterEncodingFilter
org.springframework.web.filter.CharacterEndodingFilter
encoding
utf-8
forceEncoding
true
characterEncodingFilter
/*
springMVC
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:springmvc.xml
1
springMVC
/

springmvc.xml

Controller

package com.monkey1024.controller;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;@Controller@RequestMapping("/user")public class ParamsController01 {		/*	 * 表单参数名称和方法参数名称不一致的情况	 */	@RequestMapping("/params02")	public ModelAndView getParams02(@RequestParam(name="username") String t_username, @RequestParam(name="age",defaultValue="18") int t_age) throws Exception{		// 方法的参数名需要跟前台页面中的表单里面的input的name一致		ModelAndView mv = new ModelAndView();		mv.addObject("username",t_username);		mv.addObject("age",t_age);		mv.setViewName("result ");		return mv;	}}

regist.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"    pageEncoding="utf-8"%>Insert title here	
姓名:
年龄:

result.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"    pageEncoding="utf-8"%>Insert title here姓名:${username }
年龄:${age }

 

转载地址:http://plhsz.baihongyu.com/

你可能感兴趣的文章
MySQL中的字符集陷阱:为何避免使用UTF-8
查看>>
mysql中的数据导入与导出
查看>>
MySQL中的时间函数
查看>>
mysql中的约束
查看>>
MySQL中的表是什么?
查看>>
mysql中穿件函数时候delimiter的用法
查看>>
Mysql中索引的分类、增删改查与存储引擎对应关系
查看>>
Mysql中索引的最左前缀原则图文剖析(全)
查看>>
MySql中给视图添加注释怎么添加_默认不支持_可以这样取巧---MySql工作笔记002
查看>>
Mysql中获取所有表名以及表名带时间字符串使用BetweenAnd筛选区间范围
查看>>
Mysql中视图的使用以及常见运算符的使用示例和优先级
查看>>
Mysql中触发器的使用示例
查看>>
Mysql中设置只允许指定ip能连接访问(可视化工具的方式)
查看>>
mysql中还有窗口函数?这是什么东西?
查看>>
mysql中间件
查看>>
MYSQL中频繁的乱码问题终极解决
查看>>
MySQL为Null会导致5个问题,个个致命!
查看>>
MySQL为什么不建议使用delete删除数据?
查看>>
MySQL主从、环境搭建、主从配制
查看>>
Mysql主从不同步
查看>>