Difference between Servlet and JSP - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Random Posts

Difference between Servlet and JSP

Share This
Servlet    JSP
A servlet is a server-side program written purely on Java. JSP is an interface on top of Servlets. In another way, we can say that JSPs are extensions of servlets to minimize the effort of developers to write User Interfaces using Java programming.
Servlets run faster than JSP JSP runs slower because it has the transition phase for converting from a JSP page to a Servlet file. Once it is converted to a Servlet then it will start the compilation
Executes inside a Web server, such as Tomcat A JSP program is compiled into a Java servlet before execution. Once it is compiled into a servlet, its life cycle will be the same as that of the servlet. But, JSP has its own API for the lifecycle.
Receives HTTP requests from users and provides HTTP responses Easier to write than servlets as it is similar to HTML.
We can not build any custom tags One of the key advantages is we can build custom tags using JSP API (there is a separate package available for writing the custom tags) which can be available as re-usable components with a lot of flexibility
Servlet has the life cycle methods init(), service() and destroy() JSP has the life cycle methods of jspInit(), _jspService() and jspDestroy()
Written in Java, with a few additional APIs specific to this kind of processing. Since it is written in Java, it follows all the Object Oriented programming techniques. JSPs can make use of the JavaBeans inside the web pages


In MVC architecture Servlet acts as controller. In MVC architecture JSP acts as a view. Servlet advantages include:

  1. Performance: gets loaded upon the first request and remains in memory indefinitely.
  2. Simplicity: Run inside a controlled server environment. No specific client software is needed: a web browser is enough
  3. Session Management: overcomes HTTP's stateless nature
  4. Java Technology: network access, Database connectivity, j2ee integration

JSP Provides an extensive infrastructure for:

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

Happy Exploring!

No comments:

Post a Comment