Jeff Chen wrote:

> Kirdorffer,
>
>    Thanks for your message. I assume the JSP preprocessor has to generate Java
> code using servlet in a fairly generic way. It is like the performance different
> between C++ and assembly. If you hand write assembly, you probably has higher
> performance. Nowdays, however, the different between C++ and assembly is not
> great for most applications, so people choose C++. Is it true that the JSP to
> Servlet compilation is so simple that performance difference between JSP and
> hand written Servlet is very minimal?
>
>    Jeff
>

The output of the JSP preprocessor for a given page is not at all "generic", any
more than the object code created by a compiler for a given source module is
"generic".  The whole focus is to create a Java class that, once compiled, creates
the single page which it is processing according to the JSP spec's semantics rules.

I would suggest that not only is the difference likely to be minimal, but a JSP page
that creates a given output could well be faster than the equivalent page
implemented via a servlet.  The reason for this is that a JSP implementation can
spend some effort optimizing the output of the template text (i.e. that part of the
page that is not JSP actions and scriptlets).  For example, if the servlet really
did use out.println() type output with no buffering, you'd probably see the JSP page
be faster.  (Think of what an optimizing compiler does to a C++ program's
performance :-).

Of course, in reality the differences really will be minimal for most pages.  To
prove it to yourself, code a non-trivial page both ways and run the JSP version
through the JSWDK JSP engine with the "keepgeneratedsource" option set.  What you
will see is a pattern of intermixed sequences like this:

* Output template text (out.println() or whatever in your servlet,
  some internal mechanism of the JSP engine for the JSP page).
  Most JSP preprocessors will consolidate all the template text
  between two actions into a single byte array that can be output
  with a single method call.

* Execution of the scriptlets and JSP actions.  For example,
  <jsp:forward> is translated into something that ultimately
  calls RequestDispatcher.forward() just as your servlet does.
  The execution time of either approach is pretty much identical.

There are valid reasons to choose between JSP and servlets for creating your HTML
(or using a hybrid design approach that uses servlets for business logic and JSP
pages for presentation logic), but speed of creating the output page is not going to
be one of them.

Craig McClanahan

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to