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
-
HTTP Response Handling (3 messages)
- Posted by: Daniel Westerdale
- Posted on: August 31 2001 09:18 EDT
Threaded Messages (3)
- HTTP Response Handling by Weston Aiken on August 31 2001 14:42 EDT
- HTTP Response Handling by Daniel Westerdale on September 03 2001 04:59 EDT
- HTTP Response Handling by Weston Aiken on September 04 2001 09:57 EDT
- HTTP Response Handling by Daniel Westerdale on September 03 2001 04:59 EDT
-
HTTP Response Handling[ Go to top ]
- Posted by: Weston Aiken
- Posted on: August 31 2001 14:42 EDT
- in response to Daniel Westerdale
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
-
HTTP Response Handling[ Go to top ]
- Posted by: Daniel Westerdale
- Posted on: September 03 2001 04:59 EDT
- in response to Weston Aiken
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
-
HTTP Response Handling[ Go to top ]
- Posted by: Weston Aiken
- Posted on: September 04 2001 09:57 EDT
- in response to Daniel Westerdale
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.