This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes Any alternative for servlet chaining? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Any alternative for servlet chaining?" Watch "Any alternative for servlet chaining?" New topic
Author

Any alternative for servlet chaining?

Rosie Vogel
Ranch Hand

Joined: Jan 31, 2001
Posts: 228
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

Joined: Dec 11, 2004
Posts: 13410

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 ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Any alternative for servlet chaining?
 
Similar Threads
Chapter 6(Session Management) notes (HFSJ) for revision
Sorry For Throwing Lengthy Codes At This Site, But I Really Need Help
SLSB & SessionSynchronization interface
Why doesn't exercise 8-1 from Murach's Java Servlets work for me on IE7?
My Shopping cart does not work