You must Sign In to post a response.
  • Category: Java Programming

    Difference Between Servlet And JSP




    What Are The Basic Difference Between Servlet And JSP Pages.JSP Work Inside Servlet Engine I Think So.
  • #8206
    .jsp files would be converted to a 'servlet' equivalent of theirs by your container (eg. Tomcat).

    So, what is jsp, would be a servlet.

    The biggest difference I know is, that usually HTTP servlets are used but the GenericServlet can be extended to implement other protocols like SMTP etc
    whereas
    jsps are defaulted to HTTPServlets only.

    So, JSPs just support HTTP protocol.

  • #8286
    Hello Mahavir Nahata,

    JSP and Servlets are both managed by Web Container.

    Actually, all the JSP code is embedded into the servlet at the last moment when the Http response is sent. You must getting the question in your mind that then why we do not write code directly into servlet? Why we use JSP's?

    We use JSP's to separate the design from the coding. All the designing is done on JSP and the programming code is written on servlets. We can also write the design code in servlet but that becomes very complex, this complex work is done by Web Container. You can see this article for more information.

    Thanks and Regards,
    Ravneet Singh
    Final keyword in Java

  • #8309
    Difference between JSPs and Servlets
    • Both JSP pages and Servlets reside on the server. JSP pages are first translated into Servlets before execution.
    • Servlets are chunks of Java code that respond to client requests but they get messy when it comes to generating content. They can be thought of as controller objects.
    • JSP pages are more like web pages with embedded Java code. They can be considered as view objects.
    • The first time a JSP is loaded, it is compiled into servlet code. This occurs only once, at translation time.
    • Subsequent requests are executed by the compiled servlet code. Handling client requests occurs at run time.
    • When you have a lot of coding and less of display, use a servlet, but if most of what you want to do is just displaying content with very little logic, use a JSP.
    • JSP pages separate design of web page from programming logic. A JSP page is a HTML page with .jsp extension. Like servlets, JSPs have both a request and a response.


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.