Jeff:

I'll try to give you some pointers, based on *my* implementation of model 2
architecture....

<snip>

>Craig gave some pseudocode for an action class that had the perform method:
>
>         public interface Action {
>           public void perform(HttpServlet servlet, HttpServletRequest
>request, HttpServletResponse response)
>                 throws IOException, ServletException;
>         } // ends interface Action
>
>(thanks Craig)

</snip>
Here's my action interface:

/* Action.java */

import java.io.IOException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;

public interface Action {
     public void perform(HttpServlet servlet,
                         HttpServletRequest request,
                         HttpServletResponse response,
                         String targetPage)
            throws IOException, ServletException;
} // ends interface Action

In my controller servlet configuration file, I specify the "default target
page" which is supposed to represent the happy days scenario. Naturally,
each individual class that implements the Action interface is free to
override/ignore the default target page if necessary.

>Now my questions are, what is the advantage is passing an HttpServlet
>object?  I understand HttpServletRequest and HttpServletResponse, but why
>HttpServlet?  Also, assuming you answer this, HOW do you pass this inside
>the servlet (sounds trivial but I have never tried any such thing)?

"I did it 'cause Craig did it this way!" Seriously, I don't recall the
specific reasons, but in a nutshell, it facilitates accessing HttpServlet
methods (and you could always cast this to your controller's class name to
do something special).

>There was mention of 2 HashTables (or HashMaps) used in the controller
>Servlet.  If I am understanding correctly, the first maps the requestURI to
>the appropriate action class, and the second is used to store an instance of
>the appropriate action class?  So, in theory, you would grab the requestURI
>and look it up in the first HashTable.  Once the appropriate class is
>determined, you look for an instance of that class in the second HashTable?
>You would then call the perform method on that class (if it exists) or
>instantiate the class and call the perform method?  I have not worked a lot
>with dynamic class loading so a little help here would be greatly
>appreciated.  Maybe a little pseudocode to get me over the hump?

Within my controller servlet I have the following:
     /**
      *  declare inner classes.
      */
     class ActionObjectWrapper {
         String theRequestUri;
         String theClassname;
         String theTargetPage;
         Action theObject = null;
     } // ends inner class ActionObjectWrapper

     /**
      *  declare member (instance) variables.
      */
     HashSet m_objectCache = null;

So, the object cache is loaded up at initialization time from the
configuration file. When a request comes in I search thru the HashSet using
the request URI as the key. If theObject is null, then you need to
instantiate it before calling perform().

>I had some concern about something craig mentioned in the brevity of his
>action classes (being 50 - 100 line mostly performing setXXX()).  In my
>servlet, I am doing all my setXXX() error checking where it seems you are
>performing this in the bean (or maybe I am just not writing as concise
>code?).  If this is the case, how do you know when the data is inappropriate
>for the field (ie, characters were found in a social security number?).  In
>my case, I do this checking in the servlet.  If an error has occured, I set
>the bean to an appropriate value (sometimes to null, and sometimes to the
>input value so that it can be easily modified by the user).  Otherwise I
>just set the bean property.  Could you go into a little more detail on this
>please?  As I mentioned earlier, it is hard to learn alternative design
>strategies when there are little to no examples to learn from =).
>
>One more thing (as if this email isnt long enough). . . I read mention of
>using yet a public HashTable (or was it a method)? to determine which page
>the action class should forward to instead of hardcoding the value within
>the action class.  Is this really all that advantageous?  I like the idea of
>having logic names mapped to a specific file name, but otherwise, this seems
>to be overhead in projects that dont span hundreds of pages (or dont have
>the possibility of spanning that large).  I assume, in this strategy, the
>action class would lookup the logical name prior to forwarding to the .jsp
>refered to in the controller servlet?
>
>I hope this all makes sense.
>
>Thanks to everyone for helping me in understanding some of these basic
>issues I am having.  I look forward to your replies :).
>
>Thanks
>
>Jeff

Hope I've answered *some* of your questions - don't have time for more
right now....

Mike

===========================================================================
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