Hi,
I too did our first go at JSP and JavaBeans with Model 1. There are a few
factors that led me to start using the Model 2 approach. We have had quite a
bit of discussion in this list lately about it. Namely, myself, Craig and
Daniel, but many others have contributed to the posts.
One thing I really disliked about using JSP/JavaBean Model 1 is how much
code you may end up putting in each JSP page to handle a form. If your doing
pages that only display a bit of dynamic content, its no big deal. But to
have a JSP page call a JavaBean method to handle the form submission, as
well as to display any errors and such, it just seems to get a bit too
heavey with java code. Down the road, if the site grows alot like ours has
been doing, it starts becoming a pain in the butt to maintain each of these
pages, as well as the JavaBeans. This is my opinion, ofcourse, but I have
read many others saying the same thing. The ironic part is, our current site
uses servlets with html generation objects to send back a page via the
response..and its very difficult to construct an html page this way compared
to JSP, however...I find myself doing just the opposite now..I am putting
code into my html, and once again it is starting to look ugly to look at the
jsp pages with code thrown about.
Secondly, what happens if your site grows and you can't handle the work?
You'll need to hire another web person, and what if that person doesn't know
java? How are you going to get them to build JSP pages if they can't write
the code for the dynamic parts of the page and form handling? Your going to
be doing double-duty. Now, I realize that IDEs will soon support JSP and
JavaBeans (I think IBMs does already) with drag and drop simplicity. But
even then, to handle a form using Model 1 you still have to insert the code
to call the JavaBean, check for errors, etc. I am not sure if you can create
tag-libs to handle all this, but imagine writing a tag-lib for each JSP page
with a form on it! It seems over kill to me.
I have opted to move to Model 2 with the single instance controller servlet,
single instance action classes, and logic classes (ejb/javabeans). The JSP
page still uses a little bit of java, but usually it will only be a
<jsp:useBean..> tag and some <%= mybean.getXXX() %> calls. With the up and
coming IDEs supporting this, using a JavaBean drag/drop onto a page will
automatically do this for the web person, so they don't need to know any
java. Plus, if you follow our look up the archives of our posts here about
the topic, by using an XML file (or property file) for configuration, you
can dynamically change the workflow of your site while the server is
running. Ofcourse..its best to do a controlled restart, but as I am
proposing to my boss, what if you have a high-traffic site, or lots of money
going through it via even a few transactions..you can't afford to be done
even for an emergency fix of bad code. However, by using the hashtable
lookup methods for classes in the controller servlet, you can easily write
an Admin tool that will "change" the class to be called mapped to a given
action to another class you just loaded. Thus, if an action class is bad,
you can fix the class, move it up to your production server giving it a
different name for the time being, access the hashtable (stored in the
servlet context) and change the class the action calls all while the server
is running to give an immediate fix. Sure, the bad class is still in memory,
but all subsequent calls will use the new fixed class. Then, later on when
you can, you shut the server down and restart it, loading up the new fixed
class (ofcourse..recompiling it to the "old" name again) and your set!
I still think its a good idea to always have a 1-hour or so service time
every day for backups, maintenance, etc, just in case. This way your clients
know that at such and such time, the site might not be reachable. This is
dependent on the type of site too. I work on a B2B, so its easier to do this
when we work on US hours..late night nobody is using our site.
Feel free to ask any questions.
===========================================================================
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