in MVC controller, for example
- TestController extends MultiActionController
TestController extends MultiActionController
1. 转到空白页面
- public ModelAndView testMVC(HttpServletRequest req,HttpServletResponse res) throws Exception {
- return null;
- }
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;
- }
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);
- %>
<%
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;
- }
public ModelAndView testMVC(HttpServletRequest req,HttpServletResponse res) throws Exception {
res.setStatus(401);
return null;
}
转载于:https://blog.51cto.com/ajiao13/1138992