赞
踩
当我们想对不合法或不存或不符合要求的请求进行跳转时,可已选择Filter来实现,下面是简单的例子
只需要在doFilter中实现内部逻辑即可
//业务逻辑
HttpServletRequest request = (HttpServletRequest)servletRequest;
HttpServletResponse response = (HttpServletResponse)servletResponse;
request.getRequestDispatcher("/views/404.html").forward(request,response);
return;
切记页面跳转,一定到return结束掉否则会出现
java.lang.IllegalStateException: Cannot forward after response has been committed
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:326)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:316)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。