I want to use HttpSession objects but I don't want the baggage that comes with them.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   A_E
Posted On:   Friday, September 20, 2002 11:37 PM

Say I don't want to use cookies or URL rewriting or some other part of the extra baggage that Sun wrapped up in HttpSessions, but I want to make use the existing objects without having to roll up my own objects. I want to do something like this: public class MyServlet extends HttpServlet { public void init() throws ServletException { //... SessionHandler[] sessionpool = SessionHandler.createSessionPool(NUM_SESSIONS); servletcontext.setAttribute("sessionpool", sessionpool); } public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { SessionHandler currentSession    More>>

Say I don't want to use cookies or URL rewriting or some other part of the extra baggage that Sun wrapped up in HttpSessions, but I want to make use the existing objects without having to roll up my own objects. I want to do something like this:

			

public class MyServlet extends HttpServlet
{
public void init()
throws ServletException
{
//...
SessionHandler[] sessionpool = SessionHandler.createSessionPool(NUM_SESSIONS);

servletcontext.setAttribute("sessionpool", sessionpool);
}

public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
SessionHandler currentSession = SessionHandler.getSession();
String id = getSessionIDMyWay(request);
currentSession.setID(id);

//...
}
}




Is there anything that does what I want? I would like to be able to create() and setID() for sessions, as well as manage persistence on my own.



Before you ask "why?" and explain to me why I really do want to do it the way that sessions have been implemented, realize that the best answer I can come up with is "because." Of course I'm also eager to learn "why" my practice is stupid, and why I really do want to handle sessions the way Sun taught me to, as long as the answer isn't simply "because."    <<Less

Re: I want to use HttpSession objects but I don't want the baggage that comes with them.

Posted By:   Jeanne_Boyarsky  
Posted On:   Saturday, September 21, 2002 06:00 AM

You really do want to do this the way Sun taught you to. Here are several reasons:

  1. There is no extra overhead for features you don't use, such as cookies and URL rewriting. (Note that these features are a part of the HttpRequest object and not the session)

  2. The request object is used by the browser. You can't change it to make it more efficient.

  3. This is a standard. If anyone ever has to maintain your code, they will understand it the traditional way.

  4. The HttpRequest and HttpSession code is already written. Most programmers aren't big fans of reinventing the wheel.

About | Sitemap | Contact