Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why JSP why not Directly Servlet!....

 
Bidyut Padhi
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends
Why we will use JSP and not servlet.Because JSP pages are again compiled into servlet and produces the Out put.
Why I will follow this indirect process in which scenario.
What are advantages in JSP over servlet (Regarding performance)?
regards
Bidyut
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is essentially no performance difference between JSP and servlets, except the first time a JSP is referenced, when it is compiled to a servlet. After that there is only a tiny overhead in dispatching a JSP, as it checks whether it has changed since the last recompile.
JSPs are best used when a synamic page has almost all static text, with a few small dynamic parts.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSPs are a way to rapidly develop web pages, being the default web content. Hence the content type is implicitly set as text/html for you.
Servlets can return any content type and are not limitted to text based content. For example a servlet could return a dynamic image based on the input params.
 
Randall Twede
Ranch Hand
Posts: 4371
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP's can help seperate the presentation from the logic by using beans. With servlets you will have long println statements to serve up the response. However I used servlets mostly any way. I used 1 JSP because it was all html, it only need one parameter passed to it to be included in the output. With servlets you have to shut down the server in order to change a servlet code, not so with JSP.
 
Alok Pota
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I feel in general JSPs are good if your static content is more than your dynamic content. If you find yourself writing more HTML then processing logic for a given page then consider converting your servlet to a JSP. I like servlets because they easily lend themselves to OOP and offer better control.
Regarding performance, I think I read somewhere that the JspWriter was slightly more optimized compared to the servlet PrintWriter and hence *could* be faster.

A crude comparison: JSP ~driving with automatic transmission, Servlet ~ driving with a stick-shift. The later gives better control. The former is easier.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic