0
2.2kviews
Differentiate between JSP and servlets.

Mumbai University > Information Technology > Sem 4 > Web Programming

Marks: 5M

Year: May 2015

1 Answer
0
9views
Servlet JSP
1. A servlet is a server-side program and written purely on Java. 1. JSP is an interface on top of Servlets. JSPs are extension of servlets to minimize the effort of developers to write user interfaces using Java programming.
2. Servlets run faster than JSP. 2. JSP runs slower because it has the transition phase for converting from JSP page to a Servlet file. Once it is converted to a Servlet then it will start the compilation.
3. Servlet executes inside a Web server, such as Tomcat 3. A JSP program is compiled into a Java servlet before execution. Once it is compiled into a servlet, it's life cycle will be same as of servlet.
4. It receives HTTP requests from users and provides HTTP responses 4. It is easier to write than servlets as it is similar to HTML.
5. We cannot build any custom tags using servlets. 5. One of the key advantage 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 the re-usable components with lot of flexibility
6. Servlet has the life cycle methods:,init(), service() and destroy() 6. JSP has the life cycle methods : jspInit(), _jspService() and jspDestroy()
7. In MVC architecture Servlet acts as controller. 7. In MVC architecture JSP acts as view.
8. Servlet advantages include: 1. Performance : get loaded upon first request and remains in memory indefinitely. 2. Simplicity : Run inside controlled server environment. No specific client software is needed, web browser is enough. 3. Session Management : overcomes HTTP's stateless nature. 8. 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.

Servlet Life cycle methods:

enter image description here

JSP Life Cycle methods:

enter image description here

Please log in to add an answer.