• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlets Vs JSP

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Performance wise which is better ? Servlets or JSP.
Pl give me some comparisons
 
Greenhorn
Posts: 27
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
load on startup implementation for a jsp is mess in many servers. so dont rely on that .
 
Ranch Hand
Posts: 530
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Servlet is compiled once, whereas JSP may be re-compiled at runtime, so JSP maybe slower than servlet.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic