When the user exits the system, if you reopen the page after the login, you should jump to a page that prompts the user not to sign in, which is easy to do, as long as the head of the JSP page plus the validation session code can be. However, because the browser has a cache, you can back, if you exit the system back, you can still open the user page before exiting. How do I prevent a cached page from being loaded back?
On the internet to find a way to set up a JSP can not be cached, the code is as follows:
<%
response.setheader ("Pragma", "No-cache");
Response.setheader ("Cache-control", "No-cache");
Response.setdateheader ("Expires", 0);
%>
But this method is only valid for IE.
Then I thought of a way: Because after the back, the page is also followed by the HTML code to load, such as page page in a section of code
<script>
alert ();
</script>
Back to the page, the dialog box will also pop up. Considering this, then I think can let the page to determine whether the user is logged in, if not logged in with JS jump to the prompt page. Since the JS code has to run once after it is back to the cached page, if the user is not logged in, the page will execute the jump code.
At this point, because the back to the page is complete HTML code, not with the server Exchange data, so if directly embedded in the JSP code to judge, then back to the page to the JSP variable value is actually the last exchange data with the server after the cache value, will not execute JSP code. Then must require the use of HTML code with the server data exchange, that is, with JS to communicate with the server, this must use Ajax.
If you use the DWR framework, you will need to obtain the SESSION,DWR for the session using DWR as follows:
HttpSession hs = Webcontextfactory.get (). GetSession ();
Then the session is judged, and a value is returned. JS based on this value to determine whether the need to jump.
There is also a problem with the DWR encapsulated function in the page, which is operated asynchronously by default. When you use DWR functions in a page to Exchange data with the server, other HTML code is loaded at the same time. At this point, you need to set the DWR to execute synchronously, that is, the code behind the called Dwr function, which needs to wait for the function to complete and then load. Set the method as follows:
Dwr.engine.setAsync (FALSE);
This setting is valid only for the current page, and the other pages are still executing asynchronously after the function that wrote the call, and then reset DWR for the asynchronous operation:
Dwr.engine.setAsync (TRUE);
The other DWR functions are still executed asynchronously after the function has been executed.