博客
关于我
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/

你可能感兴趣的文章
Mysql8.0注意url变更写法
查看>>
Mysql8.0的特性
查看>>
MySQL8修改密码报错ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
查看>>
MySQL8修改密码的方法
查看>>
Mysql8在Centos上安装后忘记root密码如何重新设置
查看>>
Mysql8在Windows上离线安装时忘记root密码
查看>>
MySQL8找不到my.ini配置文件以及报sql_mode=only_full_group_by解决方案
查看>>
mysql8的安装与卸载
查看>>
MySQL8,体验不一样的安装方式!
查看>>
MySQL: Host '127.0.0.1' is not allowed to connect to this MySQL server
查看>>
Mysql: 对换(替换)两条记录的同一个字段值
查看>>
mysql:Can‘t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock‘解决方法
查看>>
MYSQL:基础——3N范式的表结构设计
查看>>
MYSQL:基础——触发器
查看>>
Mysql:连接报错“closing inbound before receiving peer‘s close_notify”
查看>>
mysqlbinlog报错unknown variable ‘default-character-set=utf8mb4‘
查看>>
mysqldump 参数--lock-tables浅析
查看>>
mysqldump 导出中文乱码
查看>>
mysqldump 导出数据库中每张表的前n条
查看>>
mysqldump: Got error: 1044: Access denied for user ‘xx’@’xx’ to database ‘xx’ when using LOCK TABLES
查看>>