Hi,

>How do I make this work with the HashTable/Map/Set so that I can
>ensure only
>a single instance of any action class?  I assume I can load all the action
>classes into a HashSomething on the servlets init() and get the appropriate
>action and call perform()?  Is this correct?

Yeah..how do we do this? :) I would also guess in the init() call to do
something like:

{
  // read in XML config file for action class names.

  // load each instace with something like:
  for( int cntr = 0; cntr < xml_read_in_class_names; cntr++ )
  {
    Action action = (Action)
Class.forName( xml_read_in_class_names[cntr] ).newInstance();
  }
}

>So in effect I would have something like this in init? (forgive the errors
>here)
>
>        HashTable actions = new HashTable();
>        // do this for all the action classes (assuming the above code is
>used to load them)

Use HashSet? HashTable is thread safe I believe, but takes a performance hit
because of it. Since the only time you "write" to the HashSet is in the
init() method, and the rest of the time, when all requests come in, its just
searching and reading the HashSet, I believe you are "safe" from having to
use any thread-safe object like HashTable. Anyone else?

>Does this make sense or am I missing something still?

Seems about right to me. That is pretty much how I was going to implement
it, except for HashSet for performance reasons. My main concern is the time
it takes to look up the object. If you have 1000 hits at one time, can you
handle 1000 "lookups" at the same time..or is it too slow to do this?

>In my case, where I am using a variety of custom error messages
>depending on
>the field that caused the error (if the field doesnt accept negative
>numbers, it would be a special error message for the field which would then
>show up in the original form) does it make more sense to perform the
>semantic error checking in the servlet?  It seems that throwing an
>exception
>is not necessarily enough information for me.  Or even both (semantic
>checking in the servlet, but also throw exceptions in the bean if the bean
>object is reused in a non web application)?

I have had a similar question. I am curious..I know its semantically correct
to throw exceptions, but this seems odd to me if your trying to squeeze
every last bit of performance you can out of your code. Seems to me it is
much faster to return an int value, that could be used specifically as a
lookup index in the hashset for the forwarding URL, than to throw
exceptions. Again..I know the "OOP" way is to throw the exceptions, but the
overhead in creating the object, even if minimal, I can't imagine in the
case of 1000 simultaneous hits would be almost as fast as just returning an
int value as the result of the action. I have taken a step in creating a
static class that defines names for the return values, thus I have something
like

public static final   ENROLLMENT_GOOD       = 100;
public static final   ENROLLMENT_BAD        = 101;

public static final   LOGIN_GOOD            = 200;
public static final   LOGIN_BAD             = 201;

etc..

then, back in the controller servlet, it looks something like:

int result = action.perform(this,request,response);

String forwardUrl = (String)forwardTable.get(result);



>I would love to see an example of your architecture, but i realize that the
>last thing someone wants to do after a long day of work is write examples
>for the rest of us :)

Actually..I don't mind. ;)

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