为什么转发的请求会再次通过过滤器链?
我为 Grails 应用程序实现了不常见的架构,因为我制作了仅进一步转发请求的前端控制器(基于某些标准)。我还将语言环境解析器实现为 http servlet 请求过滤器。事实证明,转发的请求再次通过过滤器链。所以流程看起来像这样:
- 请求到达 grails 应用程序
- 请求通过我的过滤器
- 前端控制器获取请求并进一步转发 转发
- 的请求再次通过我的过滤器
- 后端控制器获取请求
在撰写本文的同时我已经想出了如何忽略这个问题(我的实现特定)。但我仍然很好奇为什么会发生这种情况?前锋应该在幕后工作。 Java EE 规范没有说明此行为(转发 javadoc)。
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:
- A request arrives to grails app
- The request passes through my filter
- The front controller gets the request and forwards it further
- The forwarded request passes again through my filter
- 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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
元素中,有前向
选项。它包括FORWARD
。您必须列出您希望应用过滤器的选项(请求、错误、包含)并忽略向前。In the
<filter-mapping>
element there is the forward<dispatcher>
option. It includesFORWARD
. You'd have to list the options you want the filter to be applied to (request, error, include) and leave out forward.