org.springframework.web.servlet.mvc.SimpleFormController的简单使用

页面:

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>


  
    org.springframework.web.servlet.mvc.SimpleFormController简单使用
	
	
	    
	
	
	
  
  
  
    
姓名:
年龄:

 java服务端:

package com.july;

import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController; 

import domain.Person;

public class OnSubmitController extends SimpleFormController{
	protected String success;
	protected String fail;
	public OnSubmitController() {
		setCommandClass(Person.class);//设置转换的类,Person.class为自定义的一个实体类
	}
	@Override
	protected ModelAndView onSubmit(HttpServletRequest request,
			HttpServletResponse response, Object command, BindException errors)
			throws Exception {
		System.out.println("execute ......................................");
		Person person = (Person) command;
		System.out.println(person);
		String result = "姓名:"+person.getName()+",年龄:"+person.getAge();
		Map map = new HashMap();
		map.put("result", result);
		return new ModelAndView(this.getSuccess(),map);
	}	
	public String getSuccess() {
		return success;
	}
	public void setSuccess(String success) {
		this.success = success;
	}
	public String getFail() {
		return fail;
	}
	public void setFail(String fail) {
		this.fail = fail;
	}
}
 

你可能感兴趣的:(Spring)