Thanks Celeste,
for your clear and wide explanations about this topic! :-)

Regards,
              Luca

-----Messaggio originale-----
Da: A mailing list about Java Server Pages specification and reference
[mailto:[EMAIL PROTECTED]]Per conto di Haseltine, Celeste
Inviato: gioved� 9 maggio 2002 18.53
A: [EMAIL PROTECTED]
Oggetto: FW: R: What are the advantages of the servlets and JSP pages?


Luca,

Joseph Ottinger pretty much summed up the differences between JSP and
servlets.  But I thought I would throw my 2 cents in, as I think that you
are making the learning process more difficult than it really is.

I like to think of JSP as a Rapid Application Development(RAD) way of
writing a servlet.  The first time a JSP is "touched" or called by the first
user of your web site, it is compiled by your servlet server to a "pure"
servlet.  From that point on until you "change" the code of the JSP, the
compiled servlet is used by your container, not the JSP.  Many servlet/JSP
servers, such as JRUN, also give you the ability to compile your JSP's as
part of their deployment tool, thus skipping the need for the servlet server
to compile your JSP the first time it is called.  I don't know what servlet
server you are using, but in most cases you can find the compiled servlet
that is generated from your JSP page and open it using textpad.  Doing so
may help clarify in your mind what a serlvet that is compiled from a JSP
page looks like.

As to when you should use a servlet vs a JSP page.  Every person is going to
give you a different answer to that question, and in many cases it just a
judgment call by you as the programmer as to whether you should use a Model
1 architecture (all JSP's with embedded scripting code to handle logic along
with HTML) or to use a Model 2 architecture (servlets to handle logic and
database calls, JSP to ONLY display your data using HTML and JSP tag
libraries.  Little or no Java scripting).  In some cases when I am
prototyping a new system for a client, and I have very little turn around
time, I will use a Model 1 architecture(yes, I know some people will blast
me for that, but when your under the gun for time and you don't know if you
are going to get the contract, DO NOT spend the time or money to architect a
demo, unless it's one that your sales force can reuse many times).  On
larger projects, where I have a mixture of Java/JSP experience levels, and
some people who have only graphics design and HTML experience, I will
definitely use a Model 2 architecture.  There are many flavors of Model 2
architectures, Struts is one, Maverick is another.  Which Model 2
architecture you should use is also a judgment call.  Struts is one of the
most widely know and used, but it is tightly coupled with the Jakarta JSP
tag libraries and is sometimes NOT your best option, particularly if you
have developed your own custom JSP tag libraries for your specific business
needs.  In those cases, a more lightweight MVC architecture, such as
Maverick, might suit your needs.

One last thing, Servlets in my opinion are more powerful than JSP's.  Why?
Because like any RAD tool, the JSP's constrain/limit your options.  For
example, everything that you write in a JSP page goes into the "public void
_jspService(HttpServletRequest request, HttpServletResponse response)"
method of servlet class (open up one of your compiled JSP pages and look at
it.  You will note that everything you put in the JSP page goes into the
jspService method).  And as Joseph pointed out, this limits your capability
to handle things like binary data/images.  Where as, when you are writing a
pure serlvet, you are in essence writing a "special" form of a Java Class,
and you can directly work with all the methods that are available to you in
the javax.servlet package vs just using the javax.servlet.jsp package which
is available when you write a JSP.  Check out the J2EE documentation on
Sun's web site.

I hope this clarified some of the differences between using Servlets and
JSP's.  Again, when to use a servlet and when to use a JSP is more of a
judgment call of the architect.  There are many articles out there on the
web as to when you should use a Model 2 architecture and when you should use
a Model 1 architecture, and what the differences are between the two
architectures.  If your interested in understanding more of what those two
architectures are and the pros/cons of each, do a google.com search of the
web on Model 2 and Model 1, you will get a number of hits on articles that
you can read up on.

Celeste Haseltine, PE
Sr. Developer/Architect
MTL, Inc
Dallas, TX

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

Reply via email to