is there a way to find out if the http request is coming from a expired web page(IE Page which says webpage has expired). I am expiring a webpage on click of a back button. Now on the expired page, I do a refresh/or F5 and I want to take the user on a particular page with the error message. This particular page is my home page and request mapping is /homecontroller. I am trying to use a filter to achieve this but I dont have a way to know if the request is coming from the expired page or the login page. Can someone please help.
Example - Suppose there are 3 pages A(/controllerA) -> B(/controllerB) -> C(/controllerC).
You can achieve this using session when user login set that username or id in session attribute
session.setAttribute("userid", "21");
and keep session timeout in web.xml
<session-config>
<session-timeout>20</session-timeout>
</session-config>
when user try to access page in your filter try to validate if session is active this can be done using below code
session.getAttribute("userid");
If above code return null than redirect user to login page else allow to access your class. If session return null that it means session has expired.
To invalidate session
session.invalidate();
Hope this will help you.
In general you would need some kind of token
(parameter) passed from page B to page C to validate that request is not expired.
This would be proposed flow:
- on transition from A to B, you set in session attribute like 'expectedToken' = n
- page B on transition to C, sends also this token (eg via request parameter in GET, or hidden in POST)
- controller C, you check if expectedToken
from request is same as in session and increment expectedToken
in session. If token from request is the same as in session your transition is valid, if tokens didn't match then it was resend from expired page (since browser will use old token value, and you will have already incremented one in the session).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.