Hi,
I'm using a similar but not identical approach. In my case Action
classes don't implement an interface but extend a basic abstract class
(Action) which is the one in charge of forwarding, error control, ...
Why? Because that way my controller servlet is pretty much independent
of how I create the UI thus I can seamlessly mix in my application all
the models available.
.- Model 0: That would correspond to direct servlets but in my case that
means action classes that generate their own UI. Useful for downloading
files or other cases where a servlet would be well suited.
.- Model 1: That would correspond to plain JSP, I just have an action
class that forwards to the specified JSP without performing any
operation. These are useful when building the prototype of the
application even though afterwards they almost never stay as model 1.
.- Model 2: These action class forwards to the specified JSP, performs
exception handling... following the JSP spec.
.- XML-XSL: Using XML-XSL over model 2 introduces no changes in the
action classes. Using XML generated directly from PL/SQL, for example,
required a new base class.
This has proven to be very helpful to me, as introducing changes in the
action classes required no changes at all in the controller servlet
itself. This means I can create new action class types, like
PL/SQL->XML, or use WebMacro instead of JSP, for example. And exception
hanlding and forwarding code is just specified in one place, so no need
to rewrite it for every action class.
On the downside: Extending a base class instead of implementing an
interface has the tipical problems if you have to extend more than one
class. But as action classes are usually quite simple, this has not been
a problem for us, so far :).
I hope this helps,
Dan
PD: Regarding open source solutions to model 2... Ours is open source
and it's been on the web for a while. We don't include features like
populating bean properties or XML binding but we do have Model 2
architecture, flexible and dynamic security, application wide events,
logging, internationalization, Model 2++... I'm not Craig and we are not
Apache ;) but some people might be interested in having a look at the
source code. If you are interested ->
http://www.uib.es/c-calculo/scidlj/leaf/
-------------------------------------------
Daniel Lopez Janariz ([EMAIL PROTECTED])
Web Services
Computer Center
Balearic Islands University
-------------------------------------------
Kevin Duffey wrote:
>
> Hi,
>
> > I understand. One thing, however - I still was going to have the main
> > "controller" servlet that was going to do the routine things - check for
> > login, check for session, etc. Then *that* controller servlet was going to
> > instantiate the Action servlet and call its doGet(). But as you say, that
> > would be overkill since the Action servlet would carry a lot of
> > unnecessary
> > baggage.
> >
> > Am I right that your Action classes then just each extend the Action
> > interface and have just the one perform() method? And the Action class is
> > the one that forwards to the correct JSP page?
>
> Yes..this is correct. However, as Craig often says..your mileage may vary in
> how you implement it. Because ALL actions will forward to a JSP page, I
> decided to put the forwarding call in the controller servlet itself. The
> reason for me is that I can centrally locate the ability to catch any
> uncaught exceptions, put them in the REQUEST object, then forward to the
> right JSP page, all in one location. This means each action class does NOT
> forward, and thus the reuse of the forward call (probably minor). However, I
> DO allow the action class to return a String representing the jsp page to
> forward to. Thus, the action class still can dictate what JSP page it
> forwards to simply by returning the path and page name. This, in my opinion,
> is a bit better in design (as far as I know..correct me if I am wrong),
> because instead of placing any exceptions that may occur in each action, I
> can catch them all in the controller servlet and do it one time (code wise)
> there, and forward one time (code wise) there. I am repeating myself aren't
> I? ;)
>
> I am awaiting Craigs open-source solution to Model 2!!
===========================================================================
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