A servlet is a Java class which is used to extend the capabilities of servers that host applications accessed by means of a request-response model. Servlets are mainly used to extend the applications hosted by webs servers, however, they can respond to other types of requests too. For such applications, HTTP-specific servlet classes are defined by Java Servlet technology.
A JSP is a text document which contains two types of text: static data and dynamic data. The static data can be expressed in any text-based format (like HTML, XML, SVG and WML), and the dynamic content can be expressed by JSP elements.
Difference between Servlet and JSP
|Servlet is a java code.||JSP is a html based code.|
|Writing code for servlet is harder than JSP as it is html in java.||JSP is easy to code as it is java in html.|
|Servlet plays a controller role in MVC approach.||JSP is the view in MVC approach for showing output.|
|Servlet is faster than JSP.||JSP is slower than Servlet because the first step in JSP lifecycle is the translation of JSP to java code and then compile.|
|Servlet can accept all protocol requests.||JSP only accept http requests.|
|In Servlet, we can override the service() method.||In JSP, we cannot override its service() method.|
|In Servlet by default session management is not enabled, user have to enable it explicitly.||In JSP session management is automatically enabled.|
|In Servlet we have to implement everything like business logic and presentation logic in just one servlet file.||In JSP business logic is separated from presentation logic by using javaBeans.|
|Modification in Servlet is a time consuming task because it includes reloading, recompiling and restarting the server.||JSP modification is fast, just need to click the refresh button.|
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Difference between ServletConfig and ServletContext in Java Servlet
- Difference between Java Servlet and CGI
- Difference between JSP and ASP
- Difference Between JSP and PHP
- Servlet Collaboration In Java Using RequestDispatcher and HttpServletResponse
- Java Servlet and JDBC Example | Insert data in MySQL
- How to add Image to MySql database using Servlet and JDBC
- Javax.servlet.http.Cookie class in Java
- Starting with first Servlet Application
- The HttpSession Interface in Servlet
- Life Cycle of a Servlet
- URL Rewriting using Java Servlet
- Hidden Form Field using Annotation | Java Servlet
- JSP | Implicit Objects - request and response
- Spring MVC with JSP View
- getParameter() - Passing data from client to JSP
- Program to validate a user using JSP
- getAttribute() - Passing data from Server to JSP
- Introduction to JSP
- Exception handling in JSP
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.