This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlets Vs JSP

 
abhi
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mahesh Eshwarappa
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanx for correcting me .
Mahesh
 
Bredan Tomong
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic