Difference Between Servlet and JSP

This tutorial post highlights the important difference between JSP and Servlet technologies. This is one of the fundamental concept that confuses the many beginner Java web developers. The basic difference is that, JSP is for web page and Servlet is for Java components. Servlet is HTML in Java where as JSP is Java in HTML.

  • Java EE Complete Reference
  • A servlet is like any other java class. You put HTML into print statements like you use System.out or how javascript uses document.write.
  • A JSP technically gets converted to a servlet but it looks more like PHP files where you embed the java into HTML.

In this article we will list some of the differences between Servlet and JSP.

A servlet is a server-side programJSP is an interface on top of Servlets
Executes inside a Web server, such as TomcatA JSP program is compiled into a Java servlet before execution
Receives HTTP requests from users and provides HTTP responsesEasier to write than servlets  as it is similar to HTML.
Written in Java, with a few additional APIs specific to this kind of processingCan make use of Javabeans also
In MVC architecture Servlet acts as controller.In MVC architecture JSP acts as view.
Servlet advantages include:

    • Performance-get loaded upon first request and remains in memory idenfinately.
    • Simplicity– Run inside controlled server environment. No specific client software is needed:web broser is enough
    • Session Management-overcomes HTTP’s stateless nature

Java Technology-network access,Database connectivity, j2ee integration

JSP Provides an extensive infrastructure for:

  • Tracking sessions.
  • Managing cookies.
  • Reading and sending HTML headers.
  • Parsing and decoding HTML form data.
  • JSP is Efficient: Every request for a JSP is handled by a simple Java thread
  • JSP is Scalable: Easy integration with other backend services
  • Seperation of roles: Developers, Content Authors/Graphic Designers/Web Masters

Previous Tutorial : ServletConfig in Servlet  || Next Tutorial : MVC Architecture Using JSP and Servlet

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>