Spring/Tomcat 6 会话过期问题
我正在将 Spring MVC 用于带有本地 Tomcat 6 服务器的个人网页。我正在使用默认的 Tomcat 配置(Eclipse 默认设置的配置)。
在我的控制器中(每个页面使用一个控制器,并创建会话 bean 在它们之间传递信息),我有两种方法,一种用于捕获 POST,一种用于捕获 GET 请求方法。页面逻辑将让用户单击提交按钮,并使用“redirect:abc.htm”返回将其发送到新页面或返回到 GET 方法。
我没有明确处理 cookie,但确实拥有会话 Bean 中的所有信息,并且正在使用 Spring Security 来处理安全/用户管理。
我有一个 spring 安全配置,如果用户未经授权,可以将用户重定向回登录页面。我还有一个 ExceptionHandler 捕获 HttpSessionRequiredException,尽管这不是当我使用户会话过期时触发的(它使用我的 Spring Security 配置的逻辑)。
当会话过期时(我通过 Tomcat 管理器执行此操作),用户将被重定向回登录页面。他们在尝试执行某些操作后会被重定向(单击“提交”或重新访问除“login.htm”之外的任何页面)。
我的问题是,一旦他们回到会话过期的初始页面,如果在过期时他们单击了提交按钮,则会将它们重定向到初始页面并处理提交中的 POST 事件。
示例:
- 用户已登录,在主页上
- 用户会话过期
- 用户在主页上单击提交按钮
- 用户被重定向回 login.htm 页面
- 用户登录并导航回主页。
- 它们没有遵循主页的 GET 逻辑,而是被视为主页的 POST,并且我不确定 POST 变量来自哪里。
有什么方法可以追踪这个错误来自哪里或者到底是什么原因导致的?
I'm using Spring MVC for a personal webpage with a local Tomcat 6 server. I'm using a default Tomcat configuration(what eclipse would setup by default).
In my controllers(using one controller for each page, and creating Session beans to pass information between them) I have two methods, one for capturing a POST and one for capturing a GET Request Method. The page logic will have the user click a submit button and will use a "redirect:abc.htm" return to send them to a new page or back to the GET method.
I'm not explicitly handling cookies, but do have all the information in Session Beans and am using Spring Security to handle security/user management.
I have a spring security configuration to redirect the user back to the login page if they are not authorized. I also have an ExceptionHandler catching HttpSessionRequiredException, though this is not what is triggering when I expire the user sessions(it's using the logic of my Spring Security configuration).
When the session is expired(I'm doing this through Tomcat manager) the user is redirected back to the login page. They are redirected after they try to do something(click a submit, or revisit any page except login.htm).
My issue is that once they get back to the initial page that their session expired at, if at the time of expiration they clicked a submit button, it is redirecting them past the initial page and handling the POST event from the submit.
Example:
- User is logged in, and on the main page
- User Session Expires
- User, on the main page, click a submit button
- User is redirected back to the login.htm page
- User logs in and navigates back to the main page.
- Instead of following the logic of the GET for the main page, they are treated to the POST of the main page, and I'm not sure where the POST variables are coming from.
Is there any way to trace where this error is coming from or what exactly is causing it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是由 spring-security 完成的。 Spring security 在将用户重定向到登录页面之前将请求详细信息存储在会话中。成功登录后,它将从会话中检索请求详细信息并重定向到该会话。
您可以设置 form-login 配置来覆盖此行为。
This is done by spring-security. Spring security stores the request details in the session before redirecting the user to the login page. On successful login it will retrieve the request details from the session and redirect to that.
You can set the
always-use-default-target
attribute of the form-login configuration to override this behavior.