HTTP Response Handling

Discussions

Web tier: servlets, JSP, Web frameworks: HTTP Response Handling

  1. HTTP Response Handling (3 messages)

    Hi there,


    I am attempting to build a stateless J2EE application, where the enterprise tier consists of a number of stateless (screen manager) Session EJBs, each of which handle the user interactions for a given form.

    For any HTTP Request, I have a single Main Servlet which instantiates a RequestHandler subclass based on the extra path information URL.

    The Request Handler subclass will find/create the appropriate screen manager EJB and parse any returned data into Value objects.

    So far so good. Now I want return the contents of the above value object in the appropriate HTTP response. So which of the folling options will best
    suit me needs:

    1)Do I pass the HTTP response object to the instantiate RequestHandler subclass and deal with it there?
    2)Do I stuff the value object in the session and redirect to another servlet?
    3)Do I create a common 'codec' class ( as in the latest SUN Blueprint sample: Smart Ticket application), handle the responses for all my RequestHandlers?

    Regards

    Daniel
    westerdaled at bigfoot dot com

    Threaded Messages (3)

  2. HTTP Response Handling[ Go to top ]

    Following the Model 2 JSP/Servlet Architecture, you would have the servlet add your value object(or some subset of it) to the HttpServletRequest as an attribute, and then forward the request to a JSP for presentation.

    request.setAttribute("value_obj",obj);

    getServletContext().getRequestDispatcher("/somefile.jsp").forward(request,response);

    The have your JSP(or a customer tag) pull out the attribute for presentation.

    HTH


  3. HTTP Response Handling[ Go to top ]


    Weston,

    Thanks for the advice. As each Request Handler is resposible
    for their Value object, I will need to pass the HTTP response object as an additional parameter to each overidden request handler service method e.g rh.processRequest(reg, resp). I will then need to add your lines of code at the end of each method in order to perform the redirection.

    On reflection ( no pun intended), as an alternative to the above, I could get the Servlet to interogate each instance
    of the Request Handler subclass and aquire value object, prior to perfoming the redirection.

    Which of the two approaches do you think is worth persueing?

    cheers

    Daniel



  4. HTTP Response Handling[ Go to top ]

    Daniel

    I would suggest having the servlet do the actual forwarding since it is the controller. You could either use reflection to get the value object, or ask the handler for the reference to its value object through a getter. You sort of break the encapsulation of the RequestHandler by interogating it with reflection.

    If you are still in the design stage of your project, you may want to take a look at the Apache Struts Framework. Its very similar to what your doing. It uses a main servlet, request handlers, action objects, etc...

    Good luck

    Weston

    after reading my first response, I meant "custom" jsp tag, not "customer" tag.