File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlets Vs JSP

 
Mathew Sam
Ranch Hand
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Performance wise which is better ? Servlets or JSP.
Pl give me some comparisons
 
Les Dsouza
Greenhorn
Posts: 27
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. JSP is actually converted into a servlet by the container.
2. JSP is usually used for displaying the data etc to the user whereas servlets are generally used for back end processing.
3. When a JSP is called for the very first time the response will be slow because of the process of converting it into a servlet and compiling. Thereafter it will be ok.
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Architecturally, It's not either/or it's usually both/and. Most systems use both Servlets and JSP's -- Servlets are Controllers (in an MVC Sense) and JSP's are views.
Trying to use JSP's as controllers is what often makes all-JSP sites slower. When they are used in the right way, then they're usually not a performance problem.
Kyle
 
Shashank Hiwarkar
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Mathew,
JSP has the advantage of seperating the presentation layer and business logic, and hence convinient at development.
First time when JSP engine encounter JSP request, it convert JSP in servlet, compile it and the bytecode format it saves in JSP Container along with the time stamp.
Due to this process the first time response of JSP as compaired to servlets is slower, much slower.
But from next request onword JSP engine checks the time stamp of the request and of JSP compiled file in JSP Container in JVM, and if the file is not changed then it redirects this request to that class file. And client get the response.
In case of servlet the compiled servlet, ie class files are stored in Servlet Container in JVM.
As both servlet and JSP is handled with same processes and sharing the resourses (JVM), there is no difference in performance of both.
IF anybody can throw more light on this, then please..
 
bonthu anil kumar
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shashank Hiwarkar wrote:Hello Mathew,
JSP has the advantage of seperating the presentation layer and business logic, and hence convinient at development.
First time when JSP engine encounter JSP request, it convert JSP in servlet, compile it and the bytecode format it saves in JSP Container along with the time stamp.
Due to this process the first time response of JSP as compaired to servlets is slower, much slower.
But from next request onword JSP engine checks the time stamp of the request and of JSP compiled file in JSP Container in JVM, and if the file is not changed then it redirects this request to that class file. And client get the response.
In case of servlet the compiled servlet, ie class files are stored in Servlet Container in JVM.
As both servlet and JSP is handled with same processes and sharing the resourses (JVM), there is no difference in performance of both.
IF anybody can throw more light on this, then please..



Hi Friends,
We can make the application more efficient and decrease the time when the request has been sent for the 1st time
by using the tag <load-on-startup> in web.xml file.

By doing theis the server will convert the jsp to servlet and also create the .class file for the corresponding servlet at the deployment time only.

so, I think its some what a better approach.

If there are any problems by doing so, please let me know.
I'm ready enough to accept my mistakes.

Thanq.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
load on startup implementation for a jsp is mess in many servers. so dont rely on that .
 
Nam Ha Minh
Ranch Hand
Posts: 502
Eclipse IDE Firefox Browser Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Servlet is compiled once, whereas JSP may be re-compiled at runtime, so JSP maybe slower than servlet.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nam Ha Minh wrote:Servlet is compiled once, whereas JSP may be re-compiled at runtime, so JSP maybe slower than servlet.


Only on the first translation. And it's usually pretty much unnoticeable.

But all of this is micro-optimization. The maintainability you lose by using Servlets rather than JSP is huge, whereas any performance difference will be irrelevant to the end user.
 
Paul Clapham
Sheriff
Pie
Posts: 20161
24
MySQL Database
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It may also be possible to compile your JSPs at the time you install your web application -- some servers support that option.
 
Anna Harris
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
People use JSP and Java servlets together to provide dynamic content. They prefer the easy coding experienced with JSP while avoiding the compile/debug cycle that is associated with programming languages. They also like the speed advantage provided by servlets and on the fly translation and compiling has become a usual practice in creating dynamic content with JSP and Java servlets.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic