JSP comparison Servlet

JSP comparison Servlet:

  • From a coding point of view if we want to send text to back to a response. The Servlet way is:
    response.write(“<p>Hello</P>”);

    The JSP is:
    <p>Hello</P>

  • JSPs are compiled to servlets, effectively allowing you to produce a servlet by just writing the HTML page, without knowing Java. Of course, in practice, to get anything serious done, you need to use some server-side code in there.

 

  • If you write servlets, you need to know Java to write the servlet body, and HTML to write the output.
  • The real advantage of JSP is the use of special tags that allow you to call Java beans directly, and the ability to produce your own custom tags (in Java) to do stuff that you can’t do with a single call to a Java bean (e.g. inserting a list of items into the HTML, which needs a loop construct).
  • So JSP allows you to put real Java directly into the HTML inside special tags.
  • All this Java code will be executed before the HTML is sent to the client, and is generally used to modify the HTML page. Ironically, individuals producing JSP applications on their own often end up with a JSP containing HTML, JavaScript, and Java all in the one file, which can be a little confusing, especially with all the JSP tags scattered around!
  • JSP is a serverside technology to make content generation a simple appear.The advantage of JSP is that they are document-centric. Servlets, on the other hand, look and act like programs. A Java Server Page can contain Java program fragments that instantiate and execute Java classes, but these occur inside an HTML template file and are primarily used to generate dynamic content. Some of the JSP functionality can be achieved on the client, using JavaScript. The power of JSP is that it is server-based and provides a framework for Web application development.
  • JSP doesn’t provide any capabilities that couldn’t in principle be accomplished with a servlet. In fact, JSP documents are automatically translated into servlets behind the scenes. But it is more convenient to write (and to modify!) regular HTML than to have a zillion println statements that generate the HTML. Plus, by separating the presentation from the content, you can put different people on different tasks: your Web page design experts can build the HTML

Leave a Reply

Your email address will not be published. Required fields are marked *