• 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

RequestDispatcher query

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
reply
    Bookmark Topic Watch Topic
  • New Topic