• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

design issue

 
Raj Bhandari
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • 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
 
Stefan Evans
Bartender
Posts: 1691
10
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64716
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rather than forwarding from the servlet to the JSP, use a redirect.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64716
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<Stefan and Bear bump heads> Ow!
 
Raj Bhandari
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64716
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64716
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Place them on the query string.
 
Raj Bhandari
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh yes, thats smart
Thanks Bear!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic