| Author |
design issue
|
Raj Bhandari
Ranch Hand
Joined: Oct 19, 2005
Posts: 97
|
|
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
Joined: Jul 06, 2005
Posts: 1005
|
|
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
Joined: Jan 10, 2002
Posts: 56192
|
|
|
Rather than forwarding from the servlet to the JSP, use a redirect.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56192
|
|
<Stefan and Bear bump heads> Ow!
|
 |
Raj Bhandari
Ranch Hand
Joined: Oct 19, 2005
Posts: 97
|
|
|
Thanks a lot for your answers. It solves my problem.
|
 |
Raj Bhandari
Ranch Hand
Joined: Oct 19, 2005
Posts: 97
|
|
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
Joined: Jan 10, 2002
Posts: 56192
|
|
|
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
Joined: Oct 19, 2005
Posts: 97
|
|
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
Joined: Jan 10, 2002
Posts: 56192
|
|
|
Place them on the query string.
|
 |
Raj Bhandari
Ranch Hand
Joined: Oct 19, 2005
Posts: 97
|
|
oh yes, thats smart Thanks Bear!
|
 |
 |
|
|
subject: design issue
|
|
|