| Author |
How to get rid of form data re submission?
|
chaitanya karthikk
Ranch Hand
Joined: Sep 15, 2009
Posts: 779
|
|
Hi everybody, I am Chaitanya, I working on a web project for our college. I have to maintain the college details so that everyone can access the details. I coded a jsp page which asks the user to enter the department details. After successful submission, the details are transfered to a servlet. There after that servlet transfers the details to a model and the details are inserted into a table. Then the servlet forwards the request to the same new_dept.jsp page
new_dept.jsp------->AddDept(servlet)--------->AddDeptModel(Model)---------------back to servlet---------->AddDept(Servlet)--------back to--------->new_dept.jsp
Then the same jsp page is sent to the client.
Here there is a problem. When the user refreshes the page an alert box is coming, saying the user that the page reloads and sends the previous data to the servlet again. iF THE USER SELECTS "OK" then the same details are sent to the servlet. So once again the same details are inserted into the database.
So I decided to forward the request to viewDepartments servlet like this.
Here again I am experiencing a problem. The viewDepartments servlet is a get request. Not a post request. The RequestDispatcher here is sending a post request to the servelt. Again I am getting an error saying the viewDepartment servlet cannot handle post request.
So I coded the viewDepartment servlet in service method. This should not be done. I know, but I dont have any alternative.
Please help me with this problem.
Thank you all in advance. Have a NICE DAY
|
Love all, trust a few, do wrong to none.
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
|
Have a search in this forum for duplicate submisions; this question gets asked a lot and has been answered before.
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
chaitanya karthikk
Ranch Hand
Joined: Sep 15, 2009
Posts: 779
|
|
|
I ll make a searh, thank you sir
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
|
Also chaitanya read this...
|
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
|
 |
chaitanya karthikk
Ranch Hand
Joined: Sep 15, 2009
Posts: 779
|
|
I changed it Ankit. Thank you for reminding me.
Coming to the topic, I did a search.
I came to a conclusion to use response.sendRedirect("new_dept.jsp"); instead of RequestDispatcher.
Is this right?
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56204
|
|
|
You might benefit from reading this article.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
chaitanya karthikk
Ranch Hand
Joined: Sep 15, 2009
Posts: 779
|
|
Hi Bear, this article is very nice. Thanks for sending me the link.
Have a nice day.
|
 |
 |
|
|
subject: How to get rid of form data re submission?
|
|
|