aspose file tools*
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
Author

Servlets Vs JSP

abhi
Greenhorn

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.
Thanks.
Mahesh Eshwarappa
Greenhorn

Joined: Jan 04, 2001
Posts: 28
Hi,

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.

Regards
Mahesh
Frank Carver
Sheriff

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 frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Mahesh Eshwarappa
Greenhorn

Joined: Jan 04, 2001
Posts: 28

Thanx for correcting me .
Mahesh
Bredan Tomong
Greenhorn

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
Rancher

Joined: Mar 22, 2000
Posts: 12789
    
    5
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>
Bill

------------------
author of:
 
Consider Paul's rocket mass heater.
 
subject: Servlets Vs JSP