• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

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.
 
Today you are you, that is turer than true. There is no one alive who is youer than you! - Seuss. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic