This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get rid of form data re submission?

 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a search in this forum for duplicate submisions; this question gets asked a lot and has been answered before.
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ll make a searh, thank you sir
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also chaitanya read this...
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might benefit from reading this article.
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear, this article is very nice. Thanks for sending me the link.

Have a nice day.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic