@RequestMapping(value="/delete") public String delete(int id) throws Exception{ System.out.println("刪除用戶->" + id); //轉發到find(int) //return "forward:/user/find.action"; //重定向到find(int) return "redirect:/user/find.action?id=4"; } @RequestMapping(value="/find") public String find(int id) throws Exception{ System.out.println("查找用戶->" + id); return "/success.jsp"; }
完整的UserAction.javajava
package com.rk.action; import java.text.SimpleDateFormat; import java.util.Date; import org.springframework.beans.propertyeditors.CustomDateEditor; import org.springframework.stereotype.Controller; import org.springframework.web.bind.ServletRequestDataBinder; import org.springframework.web.bind.annotation.InitBinder; import org.springframework.web.bind.annotation.RequestMapping; @Controller @RequestMapping(value="/user") public class UserAction { @InitBinder private void initBinder(ServletRequestDataBinder binder){ binder.registerCustomEditor( Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true)); } @RequestMapping(value="/delete") public String delete(int id) throws Exception{ System.out.println("刪除用戶->" + id); //轉發到find(int) //return "forward:/user/find.action"; //重定向到find(int) return "redirect:/user/find.action?id=4"; } @RequestMapping(value="/find") public String find(int id) throws Exception{ System.out.println("查找用戶->" + id); return "/success.jsp"; } }