Servlet, Jsp, and ServletJsp

Source: Internet
Author: User

Servlet, Jsp, and ServletJsp

DRP has been around for more than half a month, but it has not summarized the important knowledge points. Now let's take it into consideration. Now let's summarize the differences between Servlet and Jsp:

To understand their differences, you must first understand what the Servlet and Jsp are? What is it? How to use it? Then we will learn from these questions first.

Servlet is a program running on the server side to process client requests and make responses (mediation at the page and model layer ). In general, Servlet is a Java class used to process Web requests. It can dynamically generate HTML pages to the client, but there are many out. println () in the program, and the Java and HTML languages are messy together. Therefore, Jsp was launched later. So what is Jsp?

Jsp is a technical standard that enables software developers to dynamically generate HTML, XML, or other Format documents in response to client requests. In fact, Jsp is a Servlet. Each Jsp is converted into a Servlet File during the first run and then compiled into a class for running. With Jsp, in MVC mode, Servlet is no longer responsible for generating HTML pages. Instead, it serves as the control program logic to control the flow between Jsp and JavaBean.

Next, let's briefly describe the difference between Servlet and Jsp.

1. After jsp is compiled, it can be said that jsp is equivalent to servlet.

2. jsp is better at page (performance ). Servlet is better at logical editing. (Core differences ).

3. In actual applications, Servlet is used to control business processes, while JSP is used to generate dynamic web pages. In the struts framework, JSP is located at the view layer of the MVC design mode, while Servlet is located at the control layer.

I feel that the above three points are very classic. They both illustrate the relationship between them, and summarize the differences between them and their respective uses. In the future, we will gradually learn how to use these products in projects. Come on!


Differences between Servlet and JSP

Servlet is a Java program running on the server. In a sense, it is a server-side Applet. Therefore, Servlet can be embedded into Web Server as a plug-in like Applet, providing protocol services such as HTTP and FTP, and even customized protocol services. JSP is a new technology introduced by Sun following Servlet. It is developed based on Servlet. The difference between Servlet and JSP is as follows:
(1) different programming methods
JSP is developed to solve the relatively difficult programming technology in Servlet. Therefore, JSP is much easier than Servlet in programming. Servlet strictly complies with Java programming standards, JSP complies with the scripting language standards.
(2) The Servlet must be compiled before execution.
JSP does not need to be compiled separately. JSP iner automatically completes this task, and Servlet must be compiled after each code modification before execution.
(3) different running speeds
It takes some time for JSP iner to compile the JSP program into a Servlet, so the JSP running speed is slower than that of the Servlet. However, if the JSP file can be reused without any change, it will run at the same speed as Servlet in the call after the first time, because after receiving the request, the JSP iner will confirm whether the passed JSP has been changed. if no changes are made, the Servlet class compiled by JSP will be called directly and provided to the client for interpretation and execution. If the JSP file changes, the JSP iner will re-compile it into a Servlet and then submit it to the client.

What is the difference between JSP and Servlet in java?

1. What is Servlet?
Development of Client/Server Computing. Java provides a complete set of client/server solutions. In this solution, the program can be automatically downloaded to the client and executed. This is the applet. But it is only half of the problem. The other half of the problem is Servlet.
Servlet can be considered as a server-side applet. The servlet is loaded and executed by the Web server, just as the applet is loaded and executed by the browser. The servlet receives a request from a client (through a Web server), executes a job, and then returns the result. The basic process for using servlet is as follows:
· The client initiates a request through HTTP.
· The Web server receives the request and sends it to the servlet. If the servlet has not been loaded, the Web server will load it to the Java Virtual Machine and execute it.
· Servlet will receive the HTTP request and perform some processing.
· Servlet will return a response to the Web server.
· The Web server sends the response received from the servlet to the client.
Because the servlet is executed on the server, the security issues related to the applet do not need to be implemented. Note that the Web browser does not directly communicate with the servlet. The servlet is loaded and executed by the Web server.
Servlets are written in Java, so they are platform-independent at the beginning. In this way, the promise that Java can run (write once, run anywhere) on any platform can also be implemented on the server. Servlet also has some unique advantages that CGI scripts do not possess: (I am not very familiar with CGI, so these features cannot be fully understood. This is also an excerpt from the forum post. Please forgive me)
Servlet is persistent. The servlet is loaded only once on the Web server and can maintain services (such as a database connection) between different requests ). In contrast, CGI scripts are transient. Each request to a CGI script causes the Web server to load and execute the script. Once the CGI script stops running, it is cleared from the memory and the result is returned to the client. Every time a CGI script is used, it will cause repeated execution of the program initialization process (such as connecting to the database.
Servlet is not related to the platform. As mentioned above, servlet is written in Java and naturally inherits the platform independence of Java.
Servlet is extensible. Because servlet is written in Java, it has all the advantages of Java. Java is a robust and object-oriented programming language that can be easily expanded to meet your needs. Servlet naturally has these features.
Servlet is safe. The only way to call a servlet from the outside is through the Web server. This provides high-level security protection, especially when your Web server is protected by a firewall.
Setvlet can be used on a variety of clients. Since servlets are written in Java, you can easily use them in HTML, just like using an applet.
So how does the Servlet work? How to Write a Servlet? What is its basic architecture?
These questions will be introduced in the following sections.
Ii. JSP and Servlet
Now we have a rough understanding of Servlet. Now let's talk about the relationship between JSP and Servlet.
JSP is a scripting language that encapsulates the interface of the Java Servlet system, simplifies the use of Java and Servlet, and provides the ability to dynamically execute web pages by extending JSP tags. Despite this, JSP still does not go beyond the scope of Java and Servlet. Not only can Java code be directly written on JSP pages, but JSP runs only after being translated into Servlet. JSP is executed on the server and the execution result is output to the client browser. We can say that it is basically irrelevant to the browser. It is a full text with JavaScript ......>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.