How to work with users who, after clicking the "Back" button

I will show the message "You are not logged in" - for guests who clicked the "send" button on my page. Of course, for registered users, I want to not show the message. I encoded it like this:

<c:if test="${someCondition}"> addMsgToButtonEvent(); </c:if> 

It works (almost) perfectly. But now that the user is logged in and:

  • exit the context menu (which is in my header and redirects to another page)
  • Click the back button in the browser.

The message does not appear, because my page is not displayed again, addMsgToButtonEvent is not called. I know that I can lock the back button by clearing the history, but that can change a lot in business requirements. Is this a small and effective solution to this problem?


Edited by:

I think the best approach to this problem is to cancel the session after logging out. I did it this way.

+4
source share
2 answers

I had similar problems with ASP.Net sites and login controls.

You can add a meta tag to HTML to tell the browser not to cache it - therefore, the back button will reload the page from the server:

 <meta http-equiv="CACHE-CONTROL" content="NO-CACHE"> <meta http-equiv="EXPIRES" content="0"> 

Hope this can help :)

+3
source

If caching is a problem, add the following lines to the top of your JSP

 <% response.setHeader("Cache-Control","no-cache no-store"); //HTTP 1.1 response.setHeader("Pragma","no-cache"); //HTTP 1.0 response.setDateHeader ("Expires", 0); //prevents caching at the proxy server %> 

If this does not solve the problem ... you can see how you process the displayed code and the invalid session.

The best approach:

When creating a session, assign a named attribute. To print an expression, check for a named attribute. If a named attribute is found ... print a message; otherwise, do this. When logging out ... do session.invalid ()

Let me know what worked ... and we can delve into that

0
source

Source: https://habr.com/ru/post/1387167/


All Articles