aspose file tools*
The moose likes Servlets and the fly likes How to get rid of form data re submission? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to get rid of form data re submission?" Watch "How to get rid of form data re submission?" New topic
Author

How to get rid of form data re submission?

chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

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: 806

I ll make a searh, thank you sir
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

Also chaitanya read this...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

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: 61224
    
  66

You might benefit from reading this article.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

Hi Bear, this article is very nice. Thanks for sending me the link.

Have a nice day.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get rid of form data re submission?