您当前的位置: 首页 >  spring

星夜孤帆

暂无认证

  • 1浏览

    0关注

    626博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

SpringMVC基础-04-单个接受表单提交数据

星夜孤帆 发布时间:2019-04-20 21:09:48 ,浏览量:1

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




Insert title here


	
		姓名:
		
		年龄:
		
		
	

 
result.jsp




Insert title here


姓名:${username }

年龄:${age }

 

 

关注
打赏
1636984416
查看更多评论
立即登录/注册

微信扫码登录

0.0387s