- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference between Servlet and JSP
In brief, it can be defined as Servlet are the java programs that run on a Web server and act as a middle layer between a request coming from HTTP client and databases or applications on the HTTP server.While JSP is simply a text document that contains two types of text: static text which is predefined and dynamic text which is rendered after server response is received.
The following are the important differences between ArrayList and HashSet.
Sr. No. | Key | Servlet | JSP |
---|---|---|---|
1 | Implementation | Servlet is developed on Java language. | JSP is primarily written in HTML language although Java code could also be written on it but for it, JSTL or other language is required. |
2 | MVC | In contrast to MVC we can state servlet as a controller which receives the request process and send back the response. | On the other hand, JSP plays the role of view to render the response returned by the servlet. |
3 | Request type | Servlets can accept and process all type of protocol requests. | JSP on the other hand is compatible with HTTP request only. |
4 | Session Management | In Servlet by default session management is not enabled, the user has to enable it explicitly. | On the other hand in JSP session management is automatically enabled. |
5 | Performance | Servlet is faster than JSP. | JSP is slower than Servlet because first the translation of JSP to java code is taking place and then compiles. |
6 | Modification reflected | Modification in Servlet is a time-consuming task because it includes reloading, recompiling and restarting the server as we made any change in our code to get reflected. | On the other hands JSP modification is fast as just need to click the refresh button and code change would get reflected. |
Example of Servlet
JavaTester.java
import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class JavaTester extends HttpServlet { private String message; public void init() throws ServletException { // Do required initialization message = "Hello World"; } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Set response content type response.setContentType("text/html"); // Actual logic goes here. PrintWriter out = response.getWriter(); out.println(message); } }
Output
Hello World
- Related Articles
- Difference Between CGI and Servlet
- Difference Between Applet and Servlet in Java
- Difference between JSP and ASP
- What is the difference between include action and include directive in JSP?
- Difference Between & and &&
- Difference between Voltage Drop and Potential Difference
- Difference between JCoClient and JCoDestination
- Difference between localhost and 127.0.0.1?
- Difference between Process and Thread
- Difference between Bootstrap and AngularJS.
- Difference between C and C++.
- Difference between Java and JavaScript.
- Difference between NodeJS and AngularJS
- Difference between Normalization and Denormalization
- Difference between SQL and NoSQL

Advertisements