/**
* 测试重定向
*/
@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的话是转发