wood burning stoves 2.0
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes JSP more efficient than Servlet ??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "JSP more efficient than Servlet ???" Watch "JSP more efficient than Servlet ???" New topic

JSP more efficient than Servlet ???

Jaime Yong

Joined: Oct 05, 2005
Posts: 20
It is said that in some of the books that servlet is not efficient in generating HTML and instead we should use JSP. How is JSP more efficient in generating HTML since JSP is compiled into servlet before it is run ? Can some of the wizard out there help on this.

Thank You
Bernd Hennson

Joined: Jan 30, 2006
Posts: 16
i guess, the efficiency issue here is more based upon effective application design things. it might be simpler to write a simple HTML tag instead of out.println(HTML tag).
modelling like that your servlets act as the controllers and the entry-way to your business-logic (aka beans) while your jsp (which gets translated into servlets, yepp) stays quite simple and can be read/customized by e.g. webdesigners that have no clue about java programming at all.
a quickfix in design will not make your application break down, as the logic stays intact.

--<br />zoink,<br />Hennson<br /> <br />Certified-Java-Oracle-Moped
Saurabh Chaubey
Ranch Hand

Joined: Oct 16, 2005
Posts: 101
I guess the efficiency or the usage of either JSP or Servlets depends on the scenario on which one is working for example if one has to write an exhaustive HTML code and very little logic he can go for a JSP as it is very simple to format HTML in a JSP as compared to a Servlet.On the other hand if one wants to execute some logic processing code than he can opt for a Servlet (e.g. a Controller) which can than forward the request to a JSP page for the view.
One advantage of using JSP's is that you dont have to Compile the generated servlet classes yourself, the Container does it for you which is contrary to a Servlet. But some may feel that it is additional performance hit on the container in case one makes changes to a JSP.

So i would conclude that the efficiency of either JSP or Servlets depends on the design of one's Application and the knowledge about when should one use a JSP or a Servlet.

Marc Peabody
pie sneak

Joined: Feb 05, 2003
Posts: 4727

Originally posted by Jaime Yong:
It is said that in some of the books that servlet is not efficient in generating HTML and instead we should use JSP.

I'm pretty sure that efficiency here refers to the velocity of the programmer, not the server. You can code JSPs a ton faster than html-heavy servlets.

A good workman is known by his tools.
I agree. Here's the link: http://aspose.com/file-tools
subject: JSP more efficient than Servlet ???
It's not a secret anymore!