How JSP is faster than Servlets ?

can anyone tell me why and how jsp is faster than servlets. i want the detailed description of this question. thanks in advance..
[171 byte] By [simmy1] at [2007-9-26 2:13:10]
# 1

JSPs are not and cannot be faster than servlets; they are servlets.

A JSP engine parses a JSP page into a .java file; when compiled, that file runs as a servlet.

The reason to use JSP pages is to separate the logic and presentation layers of your application, not to increase your performance. In fact, JSPs are slower when first called, because the compilation process has to take place.

cafal at 2007-6-29 9:07:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
By any chance, did you want to ask why JSP coding is usually faster than servlet coding ?If yes, I think it has mainly to do with the fact that in JSP you primaraliy have markup code in a markup language wich is more intuitive than a programming language.
neville_sequeira at 2007-6-29 9:07:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Hi,

If you are running the JSP file first time that is slow becuase it needs to compile (it'll write the servlet in the background and execute that). After that it directly executed the precompiled servlet code thats why it's faster. If you do any changes to the JSP file or JAVA file (If you are calling as bean) it needs to recompile.

praveensmart at 2007-6-29 9:07:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

We had a long discussion on this a few weeks back. My feeling was that JSP could be faster than Servlets because when they are compiled, the compiler can optimise code in ways that most servlet programmers would not know how to. The whole thread is here: http://forums.java.sun.com/thread.jsp?forum=45&thread=136410

Breakfast at 2007-6-29 9:07:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

Hi simmy1,

The performance of JSP pages is very close to that of servlets. However, users may experience a perceptible delay when a JSP page is accessed for the very first time. This is because the JSP page undergoes a "translation phase" wherein it is converted into a servlet by the JSP engine. Once this servlet is dynamically compiled and loaded into memory, it follows the servlet life cycle for request processing. Here, the jspInit() method is automatically invoked by the JSP engine upon loading the servlet, followed by the _jspService() method, which is responsible for request processing and replying to the client. Do note that the lifetime of this servlet is non-deterministic - it may be removed from memory at any time by the JSP engine for resource-related reasons. When this happens, the JSP engine automatically invokes the jspDestroy() method allowing the servlet to free any previously allocated resources.

Subsequent client requests to the JSP page do not result in a repeat of the translation phase as long as the servlet is cached in memory, and are directly handled by the servlet's service() method in a concurrent fashion (i.e. the service() method handles each client request within a seperate thread concurrently.)

I hope this will help you out.

Regards,

TirumalaRao.

Developer TechnicalSupport,

Sun Microsystems,India.

rao_indts at 2007-6-29 9:07:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...