为什么转发的请求再次通过过滤器链? [英] Why does a forwarded request pass through filter chain again?

查看:154
本文介绍了为什么转发的请求再次通过过滤器链?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为Grails应用程序实现了不常用的体系结构,因为我使前端控制器仅根据某些条件进一步转发请求。我还实现了区域设置解析器作为http servlet请求过滤器。事实证明,转发的请求再次通过过滤器链。所以流程如下所示:


  1. 请求到达grails应用程序
  2. 过滤

  3. 前端控制器获取请求并进一步转发

  4. 转发的请求再次通过我的过滤器

  5. 后台控制器获取请求

在撰写本文的同时,我已经提出了如何省略问题我的具体实现)。但我仍然很好奇为什么会发生?前锋应该在幕后工作。 Java EE规范没有对此行为进行任何说明( forward javadoc )。在< filter-mapping> 元素中,存在着这样一个元素: 转发<调度员> 选项。它包括 FORWARD 。您必须列出您希望应用过滤器的选项(请求,错误,包含),然后向前退出。


I implemented not usual architecture for Grails app because I made front controller which only forwards requests further (based on some criteria). I also implemented locale resolver as a http servlet request filter. And it turned out that forwarded request passes again through filter chain. So flow looks like this:

  1. A request arrives to grails app
  2. The request passes through my filter
  3. The front controller gets the request and forwards it further
  4. The forwarded request passes again through my filter
  5. A back controller gets the request

In the mean time of writing this post I've come up how to omit the problem (my implementation specific). But still I'm curious why does it happen? Forward should work behind the scene. Java EE spec doesn't say anything about this behaviour (forward javadoc).

解决方案

In the <filter-mapping> element there is the forward <dispatcher> option. It includes FORWARD. You'd have to list the options you want the filter to be applied to (request, error, include) and leave out forward.

这篇关于为什么转发的请求再次通过过滤器链?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆