File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Servlets Vs JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlets Vs JSP" Watch "Servlets Vs JSP" New topic

Servlets Vs JSP


Joined: Dec 27, 2000
Posts: 4
Hi friends,
Fine. Please any one could explain the major diffences between Servlets and JSP. And which is faster in execution.
Mahesh Eshwarappa

Joined: Jan 04, 2001
Posts: 28

JSP's are meant for presentation purpose.
JSP, though should not contain any Java code in it, ie it shouldnt include any logic in it.
A JSP has HTML + Jsp tags for dynamic creation of pages.
Actually a JSP is being run by a Servlet called JSPServlet which creates the JSP o/p.
JSP is faster than a servlet.
But when u compile a JSP for the first time it is v.slow.
The reason is that whenever a JSP is created or its content is changed . The JSP page compiler parses the JSP and produces a servlet. After this the Ooutput servlet is loaded and compiled in memory. SO this cycle creates a lag.
But if a JSP is rerun for the second time. Ther will already be a compiled o/p servlet in the memory.
So it will be fast.
If u go thru sun's site U will get a better picture.

Frank Carver

Joined: Jan 07, 1999
Posts: 6920
I have to disagree. A JSP can't be faster than a servlet, because it is a servlet. When a JSP is first run, it is compiled to Java source code for a servlet, then the servlet is in turn compiled to Java bytecode which is run.
Once the bytecode for eaither a servlet or a JSP has been loaded and "init"ed, the performance depends entirely on what it does, not how it was generated in the first place.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Mahesh Eshwarappa

Joined: Jan 04, 2001
Posts: 28

Thanx for correcting me .
Bredan Tomong

Joined: Dec 21, 2000
Posts: 13
Why shouldn't JSPs include any logic in it? You mean even any if statements or for loops?
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13024
You can build any logic you like into a JSP - however, it does get a bit clumsy if you try to do too much.
Think of a JSP as an alternate way of creating a servlet - anything you can do in a servlet can be done in a JSP. <over-generalization>
People use JSP for applications where the HTML side of the presentation is more complex and servlets where the logic is more complex.</over-generalization>

author of:
I agree. Here's the link:
subject: Servlets Vs JSP
It's not a secret anymore!