• 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
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

design issue

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,
Please guide me whats the best way to do this in jsp/servlets.

I have a page1.jsp
I have a submit button on this page.
Onclick of that button, I need to call page2.jsp
Within page2.jsp, I am doing some processing say insert and give a "task complete" message on page2.jsp.
This works fine.
Now the problem is if the user refreshes page2.jsp, that task gets processed again. How should I prevent this ?[

I tried doing page1.jsp ->servlet1.class ->page2.jsp
but again its the same problem when they refresh because the url shows the servlet rather that page2.jsp.
Any suggestions what I can/should do ?

Thanks,
Raj
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One way to do this is to have one servlet/jsp doing the action, and then redirect rather than forward to your "success" page.

This tells the browser to issue a new request to "success.jsp"
If they refresh this page, it will just refresh the request for the success message - not the actual operation.

Of course they could push back one page, and then refresh - but it does make it a bit harder for users to screw up your application.
 
Sheriff
Posts: 67583
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rather than forwarding from the servlet to the JSP, use a redirect.
 
Bear Bibeault
Sheriff
Posts: 67583
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<Stefan and Bear bump heads> Ow!
 
Raj Bhandari
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for your answers. It solves my problem.
 
Raj Bhandari
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The only issue with the redirect is that now I can't send information to the redirected jsp page from my initial jsp/servlet, right ?

How do I go about now showing in the redirected page something like "x rows were inserted" keeping in mind the fact that the processing was done by the initial jsp/servlet ?

Thanks.
 
Bear Bibeault
Sheriff
Posts: 67583
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can send it as a parameter, store it in the session, submit it as a hidden value, and so on. But you cannot use a request-scoped variable.
 
Raj Bhandari
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bear,
I'm still confused. Could you please guide.
If I'm using this:

response.sendRedirect("finaltks.jsp");

How do I send parameters now ?
I've always like the hidden box, submit button concept to pass on values but how do I send them for a redirect ? Is it possible ? Thanks.
 
Bear Bibeault
Sheriff
Posts: 67583
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Place them on the query string.
 
Raj Bhandari
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh yes, thats smart
Thanks Bear!
 
Water proof donuts! Eat them while reading this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic