问题
I have a standard J2EE web-application running on WebLogic server. I want to handle a session timeout through the meta-data setup in web.xml. I tried to use the following setting
<error-page>
<error-code>408</error-code>
<location>/jsp/testErrorPage.jsp</location>
</error-page>
However it didn't work.
回答1:
Below is the explanation for 408 request timeout,
The Web server (running the Web site) thinks that there has been too long an interval of time between
- the establishment of an IP connection (socket) between the client (e.g. your Web browser or our CheckUpDown robot) and the server and
- the receipt of any data on that socket, so the server has dropped the connection.
For eg., lets say you are trying to login. But, because of some reasons there is no receipt of any data. Then there is a 408 request timeout.
But in your case you are trying to handle a session timeout. It means, client has not established a connection with the server for a particular period of time (for eg., 30 mins). Means, you are idle without doing any activity for 30 mins. This is the meaning of session-timeout.
For handling session timeout, you must have below code in your web.xml
<session-config>
<session-timeout>30</session-timeout>
</session-config>
Above code indicates that if you are idle for 30 mins, your session will be destroyed.
Also, you must write a custom listener which implements HttpSessionListener and configure it as a listeners in your web.xml
This code will be executed when your session times out. You can try to redirect to your error page in HttpSessionListener#sessionDestroyed
method.
If this solution was not what you were looking for, but instead you are looking for actually solving root cause of 408 error, then fixing 408 errors page might be helpful.
回答2:
Session timeout is a server side event and there is no straightforward way to notify browser of server side session time out. Meaning, the browse cannot get a response without any request. That's how HTTP works.
One of ways this typically implemented is as follows:
- Have some javascript based function on the browser which periodically checks the server side session via an Ajax Call.
- If the session is still valid, do nothing.
- If the session timed out, then redirect the user to desired page.
来源:https://stackoverflow.com/questions/18109300/redirect-to-error-page-on-session-timeout