• 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 remove item from shopping cart?

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I created a website using jsp and servlet. I made a shopping cart and got the items to display. But how can i remove the items from the cart? Next to each item is a remove button. When that is pressed the item selected needs to be removed and cart needs to refresh.

Here is the code to display the cart:


and here is the servlet:
 
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
When the button is clicked the form will submit. You need to supply an action for the form that invokes a task servlet that controls the process of removing the item from the model. That task servlet can then redirect to the page controller for the cart page which should repaint with the new list.

(I'm assuming you're not wanting to get into Ajax and removing the element without refreshing the page.)
 
Karen Wilson
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok thanks but what needs to go into the servlet to remove the item?
 
Bear Bibeault
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
i have no idea. Whatever is storing the list of cart items needs to be instructed to remove the item.

And actually, the servlet shouldn't be the component changing the model -- that should be in the model layer.

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As an aside, the presence of a "processRequest" method leads me to believe that you might be treating GET and POST interchangeably, i.e. doGet and doPost both call processRequest. If that is indeed the case, it will be a problem, since treating GET and POST the same violates the HTTP specification, and will likely lead to problems.

What you currently have in processRequest looks like it should go into doGet, whereas code for removing items from the shopping cart would go into doPost.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic