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.
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.
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.