Introduction of JSP

  • Java Server Pages(JSP) is a J2EE component.

  • JSP is Server side program which is similar to Java servlet in functionality and Design.

  • JSP provide same features found in a Java Servlet because a JSP is internally converted into Servlet when Client requests the JSP.

  • A JavaServer Page is nothing but a servlet that is automatically generated by a JSP container from a file containing valid HTML and JSP tags.

  • The JSP specification defines JSP as "a technology for creating the applications for generate dynamic Web content such as HTML, DHTML, SHTML, and XML."

  • A Real Web application can generate a lot of Web pages and each of them may need to be modified or maintenance.

  • JSP provide you to separate design from business logic, so a Web designer can take care of the HTML part while the Java developer concentrates on the programming of business functions required by the application.

JSP Life Cycle

    There are three methods in JSP:-
    1. jspInt()
    2. jspService()
    3. jspDestroy()
    • Calls the jspInit() to initialize te servlet instance.
    • It is called only once for a servlet instance.
    • It is called before any other method by Container.
    • jspService():-
    • jspService() method in the new servlet automatically generate by container.
    • Which have the same functionality and arguments as the servlet's service() method.
    • jspDestroy():-
    • It automatically called when JSP terminates normally.
    • It used for cleanup and disconnect from th database where resources used during the execution of JSP.
JSP Life cycle

JSP container will generate, compile, and deploy a servlet automatically that produces the output based on the content of the file.

JSP vs Servlet:-

JSP Servlet
JSP is better to generate pages that consist of large sections of fairly well structured HTML or other character data. Servlets are good for generate binary data, building pages with highly variable structure, and performing tasks (such as redirection).
JSP uses java code in Html. Servlet uses Html in Java code.
JSP is easy to maintenance or modified. Servlet is not easy to maintenance or modify.
JSP is slow compare to Servlet. Servlet is fast compare to JSP.
JSP uses both the method(doPost and doGet)in service(). Servlet uses only one method(doPost or doGet) in service().
JSP uses for both design and functionality. Servlet uses only for functionality.