/**
* 測試重定向
*/
@RequestMapping(value="/testRedirectOrForward.do",method = RequestMethod.GET)
public String redirect(@RequestParam("id")int id){
if(id==1){
log.info("{}重定向",id);
return "redirect:/static/redirect.jsp";
}else{
log.info("{}轉發",id);
return "forward:/static/forward.jsp";
}
}
@RequestMapping(value="/test.do",method = RequestMethod.GET)
public String red(@RequestParam("id") int id){
if(id==1){
return "redirect:/student/testRedirectOrForward.do?id="+id;
}else{
return "forward:/student/testRedirectOrForward.do?id="+id;
}
}
瀏覽器中輸入ip: http://localhost:8080/student/test.do?id=1
id=1的話會重定向,地址欄會變,不安全
id不是1的話是轉發