In a password-protected Web application, it is not only necessary to call the invalidate () method of HttpSession to correctly handle the user exit process. Now most browsers have buttons for moving back and forward, allowing users to move back or forward to a page. If you press the back button after exiting a Web application, the browser displays the cached page to the user.
In a password-protected Web application, it is not only necessary to call the invalidate () method of HttpSession to correctly handle the user exit process. Now most browsers have buttons for moving back and forward, allowing users to move back or forward to a page. If a user presses the back button after exiting a Web application and the browser presents the cached page to the user, the user may be confused and worry about whether their personal data is secure. Many Web applications force users to close the entire browser when exiting, so that users cannot click the back button. Some others use javascript, but it does not work in some client browsers. These solutions are clumsy and cannot be guaranteed to be 100% effective under any circumstances. They also require user experience.
//...
// Initialize RequestDispatcher object; set forward to home page by default
RequestDispatcher rd = request. getRequestDispatcher ("home. jsp ");
Rd. forward (request, response );
}
//...
// Allow the rest of the dynamic content in this JSP to be served to the browser
//...
Response. setHeader ("Pragma", "no-cache"); // HTTP 1.0 backward compatibility
String userName = (String) session. getAttribute ("User ");
If (null = userName ){
Request. setAttribute ("Error", "Session has ended. Please login .");
RequestDispatcher rd = request. getRequestDispatcher ("login. jsp ");
Rd. forward (request, response );
}
//...
Rd = request. getRequestDispatcher ("login. jsp ");}
}
Else {// Password does not match, I. e., invalid user password
Request. setAttribute ("Error", "Invalid password .");
Rd = request. getRequestDispatcher ("login. jsp ");
}
//...
Rd. forward (request, response );
//...
This. saveErrors (request, errors );
Return mapping. findForward ("sessionEnded ");
}
Return executeAction (mapping, form, request, response );
}