File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Data re-added when user clicks refresh Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Data re-added when user clicks refresh" Watch "Data re-added when user clicks refresh" New topic

Data re-added when user clicks refresh

Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
User enters data in jsp A which sends it to servlet B which sends the new data along with the old data (kind of like updating a datagrid) to jsp C to display the data. Now everything is okay but if the user presses refresh a message saying "will need to resend data press ok to continue" or something like that is shown in the browser and a new record is added to the DB how can i handle the refresh issue. From what i understand is the servlet called the page using getrequestdispatcher and forwards the page so the url stays the same as that of jspA rite ???. Should i use sendredirect here will that solve the problem if so what abt the attributes of the response object servlet sends to jsp C they will be erased in case of sendredirect and i dont want to add them to session. Any suggestions ??
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63844

Read this article and pay special attention to the PRG pattern.

[Asking smart questions] [About Bear] [Books by Bear]
Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
I guess i am already (sort of ) using this pattern but i do have a question at the end. Let me just re-explain my scenario - User fills a form in JSP Page A the form posts the data to servlet B. The servlet B processes the data and forwards it to a JSP page B. The Pattern however suggests that Servlet B should redirect and not forward to page B. To avoid the "how do i disable refresh" issue. This mechanism will work well for me , however the only thing is servletB adds a couple of attributes before it forwards the request object to page C and if i redirect directly from servlet B to page C I wont have those attribute available. The pattern also suggests that I introduce a page controller (servlet) the purpose of which i didnt really get. But currently the order followed in my code is

With the pageController its going to be as follows (here is the question)
PageA(posts)->PageControllerServlet(Q.What would this do?Will this process the received data from the jsp page)(Redirects)->ServletB(forwards)->PageC
I agree. Here's the link:
subject: Data re-added when user clicks refresh
It's not a secret anymore!