Hi,

Thanks for the reply.

My reply follows yours.

>This is EXACTLY what I am planning to do. I also do not like the
>to pass on every
>single request to the Controller servlet because then I need a
>form on every page
>(even when unnecessary) which I MUST submit to the Controller with
>a 'field'
>specifying the next page-id (All are JSP pages have a page-id, and
>currently we are
>planning to have a 'page-id' field on every page along with a
>'req-page-id' for
>every requested page.
>
>So, I am thinking whether to do it 'pure' Model 2 (every request
>have to filter
>thru Controller) or have <A href="xyz.jsp">XYZ</A> in certain
>situations. I think I
>will do it the second way.

Exactly. Anyone else know? What I do is, EVERY page has the SAME header and
footer. Because of this, every JSP page, including those forwarded to from
the servlet include the header.inc and footer.inc. In header.inc I do have
some scripting for a few things. First, we have the INSIDE site that has
"products" We have a product A = ORANGE colored tabs, and product B = GREEN
tabs. Much like Amazon.com has a "top" product and links below it that all
have the same color box. So, I feel all static pages should be normal links,
and allow the JSP header.inc to do the logic..it is after all display
logic...what header/color tabs to display, whether or not to display a login
menu, etc. If anyone can think of another way this should be done, please
elaborate. I dont see anything wrong with the way I am doing it, but I am
open for advise.  Thanks.

>We will use hidden fields. I agrre with you that It is easier that way.

I cant really think of any other way to have the servlet call the right
method.

>I was planning to use just 1 servlet, but I had a feeling that it
>was going to grow
>too big. I really like the approach you have taken. I have some
>trivial Qs about
>the above.

Ok.

>- How do you store specific-controller (ex: LoginServlet) objects
>in your main
>controller (like say, hashtable with key='Login' value='reference
>to LoginServlet
>object' ?

Well, I create a GenericServlet, and derive specific controller servlets
from it. So, it inherits the doPost, doGet, service, init, etc from the
GenericServlet (actually called DefaultServlet). I am actually going to work
on a generic way of having a single try..catch block that starts the action,
calls the method, and populates an Object bean using typecasting to call the
appropriate methods in the bean. When I get it done Id be happy to share it
here. I dont know if its a great model or not..but I think it will work. The
idea is simple though. Every JavaBean all the jsp pages use will derive from
DefaultBean, which will have error handling methods in it to get, set, and
check for Throwable exceptions. The header.inc will check for the
bean.isError() and if it is not null, display the error message below the
header menu. The DefaultServlet would then call a method that is overridden
in each descendant controller servlet to handle the logic. That method in
each servlet creates a bean from the DefaultServlet object...genericBean. It
then populates the bean by typecasting it to the appropriate bean type, and
sets the NAME of the bean to be stored in the session. Upon returning the
DefaultServlet is still in the try part, and it puts the bean in the
HttpSession. Each descendant controller servlet also sets the URL for the
forwarding page. The DefaultServlet then forwards to the URL set in the
descendant servlet, which allows all descendant servlets to provide any
number of URLs depending on exceptions, logic, etc. If an exception occurs
at any point, it is all propogated up the stack to the DefaultServlet, where
it is caught and then a bean.setError(error) is done. The finally block does
the forwarding, actually, to the page so that it is ALWAYS forwarded to.
Since all pages use the header.inc, I will most likely use something like an
ErrorBean or something, create it when an exception occurs, put it in the
session, and have the header.inc check for it. Not sure exactly how to get
header.inc to look for any number of beans in the HttpSession. Anyone know
if its possible to get a list of all objects in the HttpSession, iterate
through them and see if they are an instanceof DefaultBean? I think that
might work. But the problem is, if two or more beans are stored there, how
does the header.inc know which one to get and check for errors? So..that has
to be worked out still. Any ideas are welcome.


>- When do you instantiate those specific controllers (guess : main
>servlet's init()
>method)

Yep. They derive from DefaultServlet which has the init() method in it. I
get the ServletContext so that I can get the RequestDispatcher and forward
to pages.

>- I assume that you cast specifc controller's to the base-type and
>then call
>dispatch() on them ?. right ?

Not sure what you mean by this? I have doPost and doGet call execute(). Each
descendant method overrides execute to perform its logic. Each one uses a
single bean, of type Object, and typecasts it to whatever it needs to store
the proper data in the bean for the JSP page to display.

>Previously, we also had EJB in mind, but that solution seems to be
>an 'over-kill'
>for us at this moment. Also, we are short of time to research enough on EJB
>containers and Application servers (in fact, we were close to
>buying Oracle App.
>Server, had it supported JSP)

Bad move. Inside source says OAS is being replaced by DB-WEB, and OAS never
had much support nor will it.

>Any way, now I am using plain Java Beans for logic and DB classes
>(eventually to be
>replaced by EJBs later) which will implement DBIF interface. The
>EJBs later will
>implement the same interfaces.

My thought is that the servlet should create and call on a "session" object
to do all the logic. The servlet merely acts as a gateway to get the logic
done, and populate a JavaBean that the JSP page uses. Again, dont confuse my
use of session here with HttpSession. The JavaBean would actually have a
reference to the object session, which would eventually be an EJB session.

Thanks.

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