Home > Java > javaTutorial > Difference between JSP and Servlet

Difference between JSP and Servlet

青灯夜游
Release: 2019-01-30 17:25:51
Original
7291 people have browsed it

Servlet and JSP are two of the most popular Java Web technologies that generate dynamic content in Java Web applications. So what's the difference between them? The following article will introduce you to JSP and Servlet, and briefly introduce the differences between them. I hope it will be helpful to everyone. [Video tutorial recommendation: JavaTutorial]

Difference between JSP and Servlet

What is JSP?

JSP is a server-side programming technology that allows the creation of a dynamic, platform-independent approach to developing web-based applications.

JSP is basically an interface built on Servlets. The benefit is that it handles the UI part and reduces the developer's workload in designing the screen.

What is Servlet?

A Servlet is a program written purely in Java that runs on a Web or application server and acts as the interface between requests from a Web browser or other HTTP client and the HTTP server. The middle layer between databases or applications.

The difference between JSP and Servlet

1. Definition

JSP is a Text document, which contains two types of text: static data and dynamic data. Static data can be represented in any text-based format such as HTML, XML, SVG and WML, and dynamic content can be represented in JSP elements.

A servlet is a Java class used to extend the functionality of a server hosting applications accessed through the request-response model. Servlets are primarily used to extend applications hosted by web servers, but they can also respond to different types of requests. For such applications, HTTP-specific servlet classes are specified by Java Servlet technology.

2. Performance

JSP is slower than Servlet because the first step in the JSP life cycle is to convert JSP into java code and then compile it. In Performace, Servlet is faster than JSP.

3. Modify the code

In JSP, if we make any modifications, then we only need to click the refresh button and recompile and reload without restarting the server. .

In Servlet, if we modify the code, then we need to recompile, reload, restart the server>This means it is a time-consuming process.

4. Session management

Automatically enable session management in JSP. However, in Servlets, session management is not enabled by default and we need to enable it explicitly.

5. MVC mode

In the MVC mode, JSP is used to display output data, that is, in MVC it ​​is a view. However, Servlet plays the role of controller in the MVC pattern.

6. Protocol request

JSP only accepts http protocol requests; whereas, Servlet accepts all protocol requests.

7. Implicit objects

In JSP, we have implicit object support.

We do not have implicit objects in Servlet. This means that if we want to use an object, then we need to explicitly get the object from the servlet.

8. Business logic and presentation logic

In JSP, we can separate business logic and presentation logic by using javaBean technology.

In Servlet, we need to combine business logic and presentation logic.

9. Package

In JSP, the package is imported anywhere at the top, middle and bottom.

In Servlet, each package needs to be imported on top of the servlet.

10. Run

To run the JSP, there is no need to put the Servlet mapping entry into the web.xml file externally. You can put the entry for the JSP file as the welcome file. List is created.

To run a Servlet, you must put the Servlet mapping entry into the deployment descriptor file, which is the external web.xml file.

Summary

To use less request processing logic and more response generation logic, we need to use JSP.

For embracing request processing logic with less response generation logic, we need to use Servlet.

JSP is helpful for UI programmers because it is HTML embedded with some basic Java coding; and the server-side processing logic can be handled by Servlets.

JSP has a custom tag feature, which allows us to build reusable components, making it more flexible compared to servlets. JSP is very useful for session tracking, cookie management, and since each request is handled by a single thread, it is also very efficient.

The above is the entire content of this article, I hope it will be helpful to everyone's study. For more exciting content, you can pay attention to the relevant tutorial columns of the PHP Chinese website! ! !

The above is the detailed content of Difference between JSP and Servlet. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template