• 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

Any alternative for servlet chaining?

 
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have built a small webshop. When a user puts something in his/her cart, a database action follows, to make sure that the item is no longer available to other shoppers. I'm doing this because each item is unique. When the user leaves the site, the session expires after half an hour. When that happens I want to "empty the cart", i.e. make the items in the cart available again.

I have created a CartWrapper object that holds a Cart and implements HttpSessionListener. The sessiondestroyed method looks like this:



I think this is a dead end, because the forward method takes a HttpServletRequest and a HttpServletResponse as arguments and I don't have those in this class. Can anyone think of some sort of an alternative?

At first I just made CartWrapper go directly to the database but I think that is a little disgusting since I already have servlets doing all those database actions.
[ January 03, 2005: Message edited by: Rosie Vogel ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rosie Vogel:

At first I just made CartWrapper go directly to the database but I think that is a little disgusting since I already have servlets doing all those database actions.



Have you considered refactoring a bit, moving all of your database code out of the servlets and into helper beans that can be accessed from either the servlets or the session listeners?
[ January 03, 2005: Message edited by: Ben Souther ]
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Agreed with Ben. But more appropriately or specifically better make a Data Access Layer for DB operations and some Handler classes for your Business Logic. Just talking about a clear seperation.

cheers.
 
A lot of people cry when they cut onions. The trick is not to form an emotional bond. This tiny ad told me:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic