spring mvc 响应处理post请求和get请求 测试

**********web.xml**********************



  
  
    index.jsp
  
  
  
  
  	default
  	*.gif
  	*.jpg
  	*.png
  	*.ico
  	*.js
  	*.css
  
  
  
  
  	springmvc001-filter
  	
  		org.springframework.web.filter.CharacterEncodingFilter
  	
  	
  		encoding
  		UTF-8
  	
  	
  		forceEncoding
  		true
  	
  
  
  	springmvc001-filter
  	/*
  
   
  
  
  	springmvc001-servlet
  	
  		org.springframework.web.servlet.DispatcherServlet
  	
  	
  		contextConfigLocation
  		classpath:springMVC-main.xml
  	
  
  
  	springmvc001-servlet
  	/
  
  
  


**********springmvc 主配置文件**********************


    
    
	
		
			
		
	

    
    
    	
    	
    	
    	
    
    
    
    
    	
    


***********controller*********************

package com.springmvc001.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

public class TestController extends MultiActionController{

	//这里的参数不能丢
	public String testString(HttpServletRequest request , HttpServletResponse response){
		System.out.println("---testString--" + request.getParameter("username") +"---" + request.getParameter("password"));
		request.setAttribute("user", new User(request.getParameter("username") , request.getParameter("password")));
		return "ok" ;
	}
	
}


**************实体对象******************
package com.springmvc001.controller;

import java.io.Serializable;

public class User implements Serializable {

	/**
	 * 实体对象
	 */
	private static final long serialVersionUID = 1L;
	private String username ; 
	private String password ;
	public User() {
		super();
		// TODO Auto-generated constructor stub
	}
	public User(String username, String password) {
		super();
		this.username = username;
		this.password = password;
	}
}

*************请求jsp页面*******************

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>


  
        
    标题        
  
  
      
  
  
 
 
	


返回字符串 测试 userame :
password :






**************响应jsp页面******************

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>


  
        
    标题        
  
  
      
  
  
 
 
 	ok.jsp
 	



username==${user.username } , password==${user.password }



你可能感兴趣的