I'm doing it something like this:
First off, I'm using an xml file to store my configuration. This works best
for me but a simpler configuration could easily use a properties file.
The first part of the config file defines resource types (by resource I
basically mean 'pages' within the site that may be accessed). I define the
following:
<resource id="static">
<path>/</path>
<extension>.html</extension>
</resource>
<resource id="dynamic">
<path>/</path>
<extension>.jsp</extension>
</resource>
<resource id="program">
<path>/servlet/</path>
</resource>
I then create a series of stimulus defintions. These define what action to
take given a certain stimulus. The stimulus is simply a parameter called
'action' that gets defined in every form in the site. Here is a simple
stimulus definition:
<stimulus id="Login">
<action type="dynamic">login</action>
</stimulus>
So, if the current 'action' request parameter is equal to "Login", the
controller servlet should redirect to the 'login' page. Because of my use
of resource types, this gets translated into: /login.jsp (this make it
really easy to install the site in different directories on different
servers). Here is a more complex stimulus definition:
<stimulus id="ValidateInitialLogin">
<action type="program">AuthenticateServlet</action>
<intent>
<default>CheckAnnouncement</default>
<condition result="user">CheckAnnouncement</condition>
<condition result="instructor">CheckInstructorAnnouncement</condition>
<condition result="staff">CheckStaffAnnouncement</condition>
<condition result="admin">CheckAdminErrors</condition>
<condition result="error">Login</condition>
</intent>
</stimulus>
If the current action is 'ValidateInitialLogin', the controller servlet
should redirect to the AuthenticateServlet. Where my implementation differs
a bit is that I can specify different actions to take depending on the
results of the AuthenticateServlet. For instance, if this latter servlet
gets an error, it should set the action variable to 'Login'. If the
AuthenticateServlet runs and finds that the user belongs to a class of users
called 'instructor', the servlet should get the action variable to
'CheckInstructorAnnouncement'. The default tag is maybe a little
missleading - it is really supposed to indicate the default condition.
This system works pretty nicely. These 'action servlets' simply create
beans that do all the real work (connecting to databases, performing
queries, etc) and then set a (string) result code. A few lines of code at
the end of each of these action servlets redirects to the appropriate jsp or
servlet depending on the result code. I'd be interested in hearing about
how others implemented this idea (or critiques of the way I did it).
Donald
> >From: Mistroni Marco <[EMAIL PROTECTED]>
> >Reply-To: [EMAIL PROTECTED]
> >To: [EMAIL PROTECTED]
> >Subject: More on Model 2/little confused
> >Date: Tue, 11 Apr 2000 12:39:49 +0300
> >
> >Hi All,
> > i have followed many threads about Model 2 architecture, and at
> >the
> >hand i got
> >this picture(please correct me if i am wrong) listed below shortly :
> >- JSP 'sends' the request to the Servlet/controller
> >- based on 'path info' the Servlet fetches from an Hashtable the correct
> >Action class to instantiate
> >- action class does the logic, populates a JavaBean and send the request
to
> >the JSP
> >- the JSP fetches the request data and present it to the User
> >
> >Well, in this scenario something is not clear to me:
> >- how can the Action class know the URL of the JSP page to send the
> >response??? i don't want to hardcode it into the java class, and in one
> >thread Craig McClanahan wrote
> >
> > >Now, I tend to add a public method in my controller servlet that can
look
> >up actual page names from a logical name (as >someone else in this
thread
> >recommended).
> >
> >well i did not get this idea......could u pls explain me more?? for
> >example,
> >suppose that i store all the URL of the JSP in the config file..and then
> >populate (in the init() of the servlet) an Hashtable with all the
> >URL....then when i communicate it to the Action?? do i say it when i
create
> >the Action class that i am going to use???
> >
> >the other thing that is not clear is:
> >- how can i use a single instance of the various Action classes that i am
> >going to use??? sorry for this question, but i don't know much about
> >performance............will i have much disadvantages if i instantiate
> >every request a new Action class??
> >
> >can anyone that got the picture explain it better to me??
> >
> >sorry Craig, Kevin and Daniel for bothering again...
> >
> >thanx to all in advance
> >best regards
> > marco
> >
===========================================================================
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