Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Any alternative for servlet chaining?

 
Rosie Vogel
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • 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 ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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 ]
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic