0

I have mainmenu.jsp, login.jsp and logout.jsp. The flow is like the following

login.jsp --->mainmenu.jsp ---> logout.jsp

first user is able to see login.jsp and after successful login user can see mainmenu.jsp where clicking on logout button user is forwarded to logout.jsp file. In logout.jsp file if use clicks browser back button he/she can see the previous page (mainmenu.jsp) but I want to display login.jsp page. To avoid this I am checking for a variable using ajax call on load of main menu.jsp. and i can redirect the page to login.jsp. Here is a problem like flickerring issue. before server returns result my mainmenu.jsp file gets loaded. After server returns result the page is redirected to login page. I want to restrict the current page to load until any response come from server. How can i achieve this? I am using the following code in onload of main menu

$(window).load(function() {

                $.ajaxSetup({async:false});  //execute synchronously
                var isSessionExists = ""; 

                $.post("getSession", {}, function(data, textStatus, xhrObject) {
                    isSessionExists = data.split("=")[1];

                });
                $.ajaxSetup({async:true});
                if((isSessionExists.indexOf('NO')>=0)){
//                    alert("...inside condition...")
                    top.location="index.jsp";
                }else{
                    alert("....BREAK..."+isSessionExists)
                }

            });
Sunil Kumar Sahoo
  • 49,865
  • 50
  • 172
  • 240
  • Maybe a combination of setInterval and keeping the flickering portion hidden with CSS until you're ready for it? – Jeff May 17 '12 at 04:57
  • Are you using any controller(MVC) too? If yes, then it is better to check in controller if the user is authorized to view the page or not ( in other words, the user is logged in or logged out ). From controller you can return the correct page. If you are not using MVC then i suppose there must be something on server-side which can do such manipulation. Using JavaScript to do such thing is possible but not advisable. – Rakesh Juyal May 17 '12 at 05:00

1 Answers1

1

Try adding the following code snippet in your jsp

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

Also go through this excellent explantion Prevent Going Back after LOGOUT

Community
  • 1
  • 1
Mango
  • 640
  • 2
  • 16
  • 38