• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to get rid of form data re submission?

 
Ranch Hand
Posts: 806
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I ll make a searh, thank you sir
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also chaitanya read this...
 
chaitanya karthikk
Ranch Hand
Posts: 806
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might benefit from reading this article.
 
chaitanya karthikk
Ranch Hand
Posts: 806
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bear, this article is very nice. Thanks for sending me the link.

Have a nice day.
 
Story like this gets better after being told a few times. Or maybe it's just a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic