in MVC controller, for example
1. 转到空白页面
2. 转到空白页面,并打印字符
3. 转到系统错误页面
3.1 forward to one jsp and set the HTTP_STATUS in jsp file :
3.2 set the HTTP_STATUS in MVC Controller.
4. Redirect in Spring MVC
TestController extends MultiActionController
1. 转到空白页面
public ModelAndView testMVC(HttpServletRequest req,HttpServletResponse res) throws Exception {
return null;
}
2. 转到空白页面,并打印字符
public ModelAndView testMVC(HttpServletRequest req,HttpServletResponse res) throws Exception {
res.getOutputStream().write(new String("testString").getBytes());
return null;
}
3. 转到系统错误页面
3.1 forward to one jsp and set the HTTP_STATUS in jsp file :
<%
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
%>
3.2 set the HTTP_STATUS in MVC Controller.
public ModelAndView testMVC(HttpServletRequest req,HttpServletResponse res) throws Exception {
res.setStatus(401);
return null;
}
4. Redirect in Spring MVC
public ModelAndView testMVC(HttpServletRequest req,HttpServletResponse res) throws Exception {
String view = "redirect:"+redirectPath; -- redirectPaht must including the "http://"
return new ModelAndView(view, model);
}