• 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

urgent help : servlets !!!!!

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all !
my problem is that I want my servlet code to function in such a way that the user cannot go to the previous/back page even if he clicks the backspace key or back button.
I have tried using the setStatus(301) but it gives 'page cannot be displayed' error message. would appreciate if someone can help me.
thanks in advance.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi sumit vashishta!
Try this:
out.println("<html><head>
<script language='JavaScript'>window.history.forward(1);</script>");
out.println(" .......... </head><body> .......... </body></html>");
Hope this will help you.
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I am quite sure that it is not possible to avoid that. The only option in such cases is to open a new window using javascript without any toolbar, address bar etc. In this case you also need to capture right click of mouse and disable it since it is possible to go to the previous screen by that. Nevertheless, this is applicable only for the dummies, I mean normal users. You cannot prevent that from the real techies.
------------------
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Especially since alt-back arrow will go to the previous page in some browsers and I tend to do this without thinking...
If you need to be that paranoid about achieving this at any aim, a solution we came up with is this:
When the user goes to the next page, send them a page that uses the javascript window.opem to open a new page that they are allowed to view and closes the existing one. This destroys the history since it goes away with the previous window and the new window no longer has a window.
I'm not recommending this, personally I hate it, but it does solve the problem.
Dave.
 
sumit vashishta
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi jayakumar and mohamed,
will try your suggestions
thanks to both of u.
 
sumit vashishta
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi dave and others
is there any method/code in servlets or java wherein I can do the coding instead of javascript.
thanks dave
 
Jayakumar Gopalan
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sumit vashishta!
Whether it is servlets or JSP, ultimately HTML is going to be displayed in the browser. Once a page is displayed, by default browser will cache the page and its content. So, if the user click on the back button etc. to go to the previous page, browser will display the previous cached page without going contacting the server for the page content. So it is NOT possible (anyone correct me if I am wrong) to prevent the browser to show the previous page with the help of JAVA. So you have to rely on JavaScript only.
However, if you set the expiration of the page to zero, then browser will not cache the page and contacts the server to get the page content. So at this point of time, you can have some session objects to store the visited pages and prevent him to see the previous page.
Any comments ...
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's no true way to prevent a user from *viewing* an old page. He's already got that web page in his cache somewhere; one way or another he can view it. Here's what's probably your concern: You don't want him to do something out of order, or to do it twice... For instance, he's on an order form, he clicks submit, and while the results page is being processed, he clicks 'stop' or 'back' and submits it again in frustration. Now you've got two orders... am I close?
A great way to prevent this is to use a token. Here's how it's done:
While processing the request:
1) Randomly generate a token (integer).
2) Save the token to the user session.
3) Embed the token as a hidden parameter <input type=hidden ...> in the form (or forms) that you want to protect.
4) Send him the response.
While processing the following request:
5) Retrieve the token from the session.
6) Retrieve the token Parameter from the user request.
7) Compare the tokens.
8) If the tokens match, process the user's request
9) If the tokens don't match, then do not process the user's request, and instead tell the user to behave himself.
 
If tomatoes are a fruit, then ketchup must be a jam. Taste this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic