11 August, 2011

Java :- How to Logout/Signout in Java

Logout In Java (JSP/SERVLET)



Many Questions..



how to disable back button of the browser after logout?



Many Problems & questions I found when related to logout/signout .After signout/logout the browser

Back button is working and a user can go inside or previous page without again login.Once you logout/signout ,i.e. you cannot go to your working page without once again new login.But , there was

a problem after Logout/Signout the Back button is working.To avoid this for implementing proper logout/signout I solve this....



Steps:-



1. set the Session to Null (Do not invalidate the session if the jsp use other session including Login)



session.setAttribute("facultyList",null);



2. Set the necessary Header to Every Jsp having Logout/Signout Link



//Forces caches to obtain a new copy of the page from the origin server

response.setHeader("Cache-Control", "no-cache");

//Directs caches not to store the page under any circumstance

response.setHeader("Cache-Control", "no-store");

//Causes the proxy cache to see the page as "state"

response.setDateHeader("Expires", 0);

//HTTP 1.0 backward compatibility

response.setHeader("Pragma", "no-cache");



3. Check the session (Username) in jsp ,if null the redirect to Login Page.



try{

mybean=(List)session.getAttribute("facultyList");

}catch(Exception ex){}

if(mybean==null){response.sendRedirect("index.jsp");}

else{

//Do normal }







Now it will work . Enjoy and Follow Me.







No comments:

Post a Comment