The moose likes Servlets and the fly likes Why JSP why not Directly Servlet!.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Why JSP why not Directly Servlet!...." Watch "Why JSP why not Directly Servlet!...." New topic

Why JSP why not Directly Servlet!....

Bidyut Padhi
Ranch Hand

Joined: Sep 07, 2000
Posts: 121
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)?
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
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.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

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

Joined: Oct 21, 2000
Posts: 4351

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.

Visit my download page
Alok Pota
Ranch Hand

Joined: Mar 07, 2001
Posts: 185
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.
I agree. Here's the link:
subject: Why JSP why not Directly Servlet!....
jQuery in Action, 3rd edition