jQuery in Action, 2nd edition*
The moose likes JSP and the fly likes Preventing Browser Navigation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Preventing Browser Navigation" Watch "Preventing Browser Navigation" New topic
Author

Preventing Browser Navigation

JeanLouis Marechaux
Ranch Hand

Joined: Nov 12, 2001
Posts: 906
Hi,
What are the standard ways to prevent a user from navigating with the *back* or *forward* of his browser.
Is theer a special tip to prevent the *CTRL-N* too.
TIA
[ March 08, 2002: Message edited by: Bill Bailey ]

/ JeanLouis<br /><i>"software development has been, is, and will remain fundamentally hard" (Grady Booch)</i><br /> <br />Take a look at <a href="http://www.epfwiki.net/wikis/openup/" target="_blank" rel="nofollow">Agile OpenUP</a> in the Eclipse community
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

This question turns up very often and you might want to do a search in the HTML and JavaScript forum.
There isn't really any stable manner to do this on the client side, you can get better control over what gets shown to the client using the MVC pattern with a 'Front Controller'.
DOM
arun mahajan
Ranch Hand

Joined: Dec 07, 2001
Posts: 305
Dear David,
No doubt this is something related with javascript and HTMl but a very basic requirement on shopping cart etc.
By the way what is MVC pattern ? How can we use it? Any reference site for same?
regards,
Arun Mahajan
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

I couldn't find the thread I was looking for, but if you search the JSP and Servlet forums, there are several threads refering to the MVC architecture.
It will also help your searches if you know that 'MVC' (or Model-View-Controller) is a concept stolen from the SmallTalk language. It is often refered to as the 'Model 2' architecture in web apps.
Also of use will be the article on Struts written by our own Thomas Paul in the March version of the JaraRanch Newsletter.
(note that Struts helps code the MVC pattern, as opposed to 'being' the MVC pattern)
DOM
JeanLouis Marechaux
Ranch Hand

Joined: Nov 12, 2001
Posts: 906
David,
If i didn't post my thread into the HTML/Javascript thread, it's because I'm not interested in that kind of solution.
What want is a server-side way of solving the problem.
You mentioned the MVC, ok, interesting point.
But please go a little bit further.
What kind of "stuff" do you implement in your controller to handle the "back/forward" problem ?
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

With the MVC pattern there is a variant (sometimes called 'Front' or 'Global' Controllers) where all requests, regardless of what the client is asking for or who the client is, get made to the same Servlet.
This servlet decides which page gets sent to the client. There are a few options, but basically you decide on a flow of pages and make sure they get Page2 after they see (and complete) Page1.
In this scenario, if they use the back button and it results in the page being re-requested (by disabling caching etc), they think they are going from Page2 back to Page1, except that the Front Controller decides to send them Page2 again, since that is where they are supposed to be in the web app.
Therefore the forward and back buttons haven't been disabled or taken over, but they aren't any use to the client.
Opening a new window (as long as it shares the same session) works the same. The client can now have 2 windows showing the same page, and it is not recommended since it may be possible to 'corrupt' the data on the server, but they still can't get to a page they aren't supposed to.
Dave
JeanLouis Marechaux
Ranch Hand

Joined: Nov 12, 2001
Posts: 906
Thanks David.

What I understand is :
1- I have to disable caching in all my jsp pages
2- So each back/forward , refresh and CTRL-N will actually requests the server
3- then my front controller can handle the request
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Sounds like you are on your way.
You will find it easier in the long run if you use Struts (and have a look at the article by Thomas Paul).
Make sure you design the transitions from state to state in a stable manner, since its very easy to get wrong. (and don't use frames, then you'd be maintaining the state across multiple pages...)
Dave.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Preventing Browser Navigation
 
Similar Threads
JSP page time out
browser caching
Java & images
textbox drop down
downloading .cab files