What does the Web Client do

Ask a server for a resource and get a return from the server

HTTP && HTML

Both client and server know HTTP and HTML. HTML tells the browser how to present content to the user HTTP is the network protocol for communication between a client and a server on the Web

HTTP is divided into HTTP request and HTTP Response

  • http request

  1. HTTP method
  2. The URL to access the resource
  3. Parameters to be passed

** http response **

Key elements of Response: 1. Status code 2. Content type 3. What is returned

HTML is a corresponding part of HTTP

HTTP responses are divided into HTTP headers and HTTP bodies. The HTML for the response is in the HTTP body and is part of the HTTP response.

Get and POST methods in request

The specific differences between the GET and POST methods will be covered in more detail later

The get method

Post method

The MIME type

The MIME type tells the browser what type of data to receive so that the browser can display the data.

We can summarize the above with a graph:

The following will implement a simple servlet program

In MyEclipse platform, directly create a Web project, with its default content, directly run on server. Try several times to find 404 and look for web.xml

From the url of the configuration file, we know that the path to the servlet should be /Ch1Servlet but it shows 404, and we later discover that the details are wrong.

You need the Web application name in front of it to run.

conclusion

Why use Servlet&JSP?

** Servers excel at providing static interfaces. For example, if we need to add a piece of code in HTML, and let the dynamic display the current time, then the static interface is obviously unable to meet the requirements, then we will need a helper applications to help with display dynamic time, and then insert the processed results to the HTML, then returned to the server, for server, It still handles its own static interface. Servlets are server-side helper applications, Java applets that dynamically process the results. **