Free Data Structures and Algorithms Course

Subscribe below and get all best seller courses for free !!!


Subscribe to all free courses

Java Server Pages (JSP) : Advantages over Servlets and other technologies

In this section of blog, we will look into server side technologies that are popular. We will compare Other leading technologies with one of the highly used technologies called as Java Server Pages (JSP). So, What exactly do we mean by JSP ?. A JSP is a web-based powerful technology in which an html page has Java code embedded to it. It is one of the powerful technology which is implemented on server side to provide dynamic as well as static content to a client browser. It provides Java Developer and Web designer a way to execute a Java code present in a html page on the server side. Generally, the Java code embedded into an html page returns static or dynamic content upon executing on server side. The static content can be anything from normal html page, xml or simple txt etc. The dynamic content is been generated by Java code embedded into the web-page.

It is been seen that JSP and Servlets provides dynamic content to a web-page, but in a different way. Both technologies are powerful and complimentary to each other. Servlets and JSP operate quite differently and even opposite at some extent. A Servlet is a simple Java program in which html is embedded. The Java program executes on the server-side and display the result to the browser by embedding html which is output to the browser. The Servlet embed html into Java code through out.println statements.

Relation between JSP and Servlets
Usually JSP and Servlets are very closely related to each other. Each JSP is first compiled into a Servlet before it can be used. When a first call is made to JSP, it translates to Java Servlet source code and then with the help of compiler it gets compiled to Java Servlet class file. This class file gets executed in the server and result are returned back to client.    

Advantages of JSP over Servlets
  1. Servlets use println statements for printing an HTML document which is usually very difficult to use. JSP has no such tedius task to maintain.
  2. JSP needs no compilation, CLASSPATH setting and packaging.
  3. In a JSP page visual  content and logic are seperated, which is not possible in a servlet.
  4. There is automatic deployment of a JSP, recompilation is done automatically when changes are made to JSP pages.
  5. Usually with JSP, Java Beans and custom tags web application is simplified. 
 Advantages of JSP over other Technologies
  1. Active Server Pages (ASP) : ASP is a Microsoft technology. The dynamic part of JSP is written in Java, so it is more powerful and easier to use. Secondly, JSP is platform independent whereas ASP is not. 
  2. Pure Servlets : It is more convenient to write regular HTML than to have println statements that generate HTML. Allows separation of look from the content. In a JSP web designer can design web page separately and servlet programmers can insert the dynamic content separately. 
  3. Server-Side Includes (SSI) : SSI is widely supported technology for including externally defined pieces into a static web page. JSP is better because it lets you use servlets instead of a separate program to generate that dynamic part. Besides, SSI is really only intended for simple inclusions, not for real programs that use form data, make database connection. 
  4. JavaScript : JavaScript can generate HTML dynamically on the client. However, it can only access client environment. JavaScript can't access server-side resources like databases, catalogs, pricing information etc. 
  5. Static HTML : Regular HTML cannot contain dynamic information. JSP is easy and convenient. It is quite feasible to insert small amounts of dynamic data.
© 2021 Learn Java by Examples Template by Hubberspot