Spring拦截器/过滤器
我需要在我的 spring-jersey 应用程序中编写一个拦截器/过滤器,它将检查每个会话请求,并在成功时将代码传递给相应的控制器。传递此代码很重要,因为控制器将根据代码决定进一步的操作。
问: 1)是否可以在Spring中编写这种登录过滤器?如何? 2)是否可以将一些代码从拦截器传递到控制器?如何?
I need to write an interceptor/filter in my spring-jersey application, which will check every request for session and on success it will pass a code to respective controller. Passing this code is imp, because based on the code controller will decide further action.
Q:
1) Is this possible to write this kind of login filter in Spring? How?
2) Is this possible to pass some code to controller from interceptor? How?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们需要实现 ContainerRequestFilter 接口来创建 Jersey 过滤器。以下是使用 jersey 过滤器拦截和修改请求的代码示例:
添加此类后,我们需要为我们的 Web 应用程序注册此过滤器。现在我们将在 web.xml 中添加以下行:
We need to implement ContainerRequestFilter interface for creating Jersey filter. Following is the code sample for intercepting and modifying a request using jersey filter:
After adding this class, we need to register this filter for our web application. So now we will add following lines in our web.xml: