wood burning stoves 2.0*
The moose likes Servlets and the fly likes RequestDispatcher query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "RequestDispatcher query" Watch "RequestDispatcher query" New topic
Author

RequestDispatcher query

Rik Sweeney
Ranch Hand

Joined: Sep 04, 2001
Posts: 36
Hi,

I'm writing a basic shopping cart and want to avoid the problem with adding items to the cart and then repeatedly hitting refresh in the browser to add the items again. I thought using a RequestDispatcher would solve this problem.

What I do is send the request from the JSP to a servlet that adds the items to the cart and then forwarding the request onto another JSP to show the cart contents. I thought the RequestDispatcher would prevent these problems. Am I doing this wrong?

Thanks

Richard
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Close, but in these situations it is useful to use response.sendRedirect(), since this forces the client to load the page using a new request, so a reload will just reload the new page and will not result in the item being added multiple times.
Rik Sweeney
Ranch Hand

Joined: Sep 04, 2001
Posts: 36
Originally posted by David O'Meara:
Close, but in these situations it is useful to use response.sendRedirect(), since this forces the client to load the page using a new request, so a reload will just reload the new page and will not result in the item being added multiple times.


Excellent! That works a treat!

Thanks

Richard
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: RequestDispatcher query
 
Similar Threads
Shopping cart application using struts
time estimate for jdbc work?
invisible intermediary servlet
null value in session variable when showing not null in another page!
Problem with session