Spring MVC,如何让控制器处理程序处理映射处理程序之前的所有请求?
我编写了一个 Web 应用程序,其中包含勇敢的控制器和处理程序映射,所有内容都带有 Spring 3.0 和控制器注释。现在事实证明我需要简单和自定义的身份验证。我暂时不想使用ACEGI,因为我没有时间学习它。理想情况下,我希望我可以有一个例程,在每个映射处理程序之前调用,从 HttpSession 获取 userId,检查他是否已登录以及会话密钥,如果没有则重定向到登录页面。我一直在考虑拦截器...问题是您必须使用 HandlerInterceptorAdapter,它具有以下方法:
public boolean preHandle(
HttpServletRequest request,
HttpServletResponse response,
Object handler) throws Exception {
这不会让我访问与请求关联的 HttpSession。我该如何解决这个问题?
I've wrote a web app with its brave controllers and handler mapping, everything with Spring 3.0 and controller annotations. Now turns out that I need simple and custom autentication. I don't want to use ACEGI for the moment, because I've no time to learn it. I'd like ideally that I could have a routine that gets called before every mapped handler, gets from the HttpSession the userId, checks if he is logged in and the session key and if not redirects to a login page. I've been thinking about an interceptor... the problem is that you have to use HandlerInterceptorAdapter, which has the following method:
public boolean preHandle(
HttpServletRequest request,
HttpServletResponse response,
Object handler) throws Exception {
that won't let me access the HttpSession associated with the request. How do I solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你确定吗?您应该能够通过
request.getSession()
获取会话。Are you sure? You should be able to obtain the session through
request.getSession()
.