当前位置:   article > 正文

过滤器Filter实现页面跳转_过滤器filter跳转viewandmodel

过滤器filter跳转viewandmodel

当我们想对不合法或不存或不符合要求的请求进行跳转时,可已选择Filter来实现,下面是简单的例子

只需要在doFilter中实现内部逻辑即可

//业务逻辑
HttpServletRequest request = (HttpServletRequest)servletRequest;
HttpServletResponse response = (HttpServletResponse)servletResponse;
request.getRequestDispatcher("/views/404.html").forward(request,response);
return;  
  • 1
  • 2
  • 3
  • 4
  • 5

切记页面跳转,一定到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)
  • 1
  • 2
  • 3
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/算法构造者/article/detail/61323
推荐阅读
  

闽ICP备14008679号