• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

prevent back button in struts 1.x

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm new to struts. I unable to prevent back button in struts 1.x. Here is my code.

in struts-config.xml my code

<!-- logout link-->
<action path="/logout" type="com.myapp.struts.Logout_Action">
<forward name="success" path="/index.jsp"/>
<forward name="failure" path="/index.jsp"/>
whenever user click on sign out, control goes to index page. ok. but whenever user clicks on back button it is going back to previous page. here is my session code.

// check session attribute
HttpSession mySession = request.getSession();
if (mySession.getAttribute("user_id") == null || mySession.getAttribute("user_id").equals(""))
{
//response.sendRedirect("index.jsp");
return mapping.findForward(FAILURE);
}

else
{

response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
response.setDateHeader("Expires", 0);
mySession.removeAttribute("user_id");
mySession.invalidate();

return mapping.findForward(SUCCESS);
}
whenever user refreshes the page after going back then only it is going to index page. in the above code the action class is extends Action.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What the browser does when the back button is pressed is up to the browser - some simply display the previous page, regardless of cache settings. What particular problem are you trying to address by preventing that?
 
t sathya narayana
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
whenever user clicks on back button it is going back to previous page means users home page. i need to prevent that one. whenever user clicks on back button it should not display the users home page. I need to do this.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

i need to prevent that one.


My question was really: why? (Please don't say something like: it's a requirement given to me - tell us the actual reason.)
 
t sathya narayana
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ln gmail after has sign out the control goes to home page. if the user trying to come back means by clicking the back button it displays index page. same thing now im trying but im unable to prevent that. then only we can give security to end users. whenever i clicking on back button it is going to users page. otherwise other persons can see the user details after going back.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you're talking about a publicly accessible computer? People should always close the browser in those circumstances, which will prevent this kind of thing from happening.
 
t sathya narayana
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but in gmail its not like that, means no need to close a browser after user has sign out. when i'm clicking back button after sign out its going to index page no need of closing a browser. i want like this. how to do this.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gmail is a single page web app. You can use the back and forward buttons but they just point to anchors on the same page. Which means the page itself knows you have logged out and re-renders as a login page.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic