aspose file tools*
The moose likes Performance 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 » Performance
Bookmark "Servlets  Vs  JSP" Watch "Servlets  Vs  JSP" New topic
Author

Servlets Vs JSP

Mathew Sam
Ranch Hand

Joined: Dec 19, 2001
Posts: 124
Performance wise which is better ? Servlets or JSP.
Pl give me some comparisons
Les Dsouza
Greenhorn

Joined: Jan 29, 2002
Posts: 27
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

Joined: Aug 10, 2001
Posts: 3892
    
    5
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


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
Shashank Hiwarkar
Ranch Hand

Joined: Feb 17, 2002
Posts: 32
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..


Shashank Hiwarkar<br />SCJP, SCWCD
bonthu anil kumar
Greenhorn

Joined: Jul 26, 2012
Posts: 1
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

Joined: Jan 28, 2008
Posts: 5575

load on startup implementation for a jsp is mess in many servers. so dont rely on that .
Nam Ha Minh
Ranch Hand

Joined: Oct 31, 2011
Posts: 498

Servlet is compiled once, whereas JSP may be re-compiled at runtime, so JSP maybe slower than servlet.


PM Me If You Want to get Urgent Help on Java Programming
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61201
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: Aug 21, 2012
Posts: 13
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlets Vs JSP