Craig McClanahan wrote:

"Why do you need a big "if...else if" construct in Model2? The approach I
take is to use the path information part after the servlet path, and look up
the appropriate processing class in a Hashtable that is configured in the
initialization of the servlet. That way, there is no code change to the
controlling servlet when you add new processing options."


This is the approach that I'd like to use, but I'm not sure I understand it
well enough.

I might do something like this, using an interface:

String actionName = getActionName(HttpUtils.getRequestURL(request));  //
utility method of the controller servlet for getting the path after the
servlet path
Performable action = (Performable) actionMap.get(actionName);    // don't we
need new instance?


Now, how should I provide the action class with request parameters? The
examples bundled with Tomcat seem to suggest passing the request to the
class:

action.processRequest(request);

The logic in this seems to be that the action class knows best what
parameters it needs, so it extracts them from the request, checks for input
errors, and if everything is OK processes the request. Some have written
about using Java's Reflection API, but this seems like overkill and hard to
debug.

Then the controller servlet is responsible for making sure that no errors
occurred, and forwarding the request:
if (action.hasErrors()) { ...create an error bean, forward request to the
error page }
else { ...create a view bean, forward request to the requested page }

In this scenario, who should be responsible for initializing the view bean
to be sent to the jsp page, the action or the servlet, or should the action
be also the view bean?

Also, would you consider it acceptable design to allow the action class to
internally set new attributes in the current request or session via the
HttpServletRequest that it received as a parameter, for example: adding the
view bean to the request?

Thanks,
Scott

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to