The servlet's mate with the Web container:
1) The client initiates an HTTP request to the Web server.
2) HTTP requests are accepted by the Web server, and if a static page is requested, the Web server is responsible for processing. If a Java Web Component (servlet or JSP) is requested, it is handed over to the Web container. The Web container can be started in the process of the same process, different processes, or other Web service hosts of the host.
3) The Web container determines the specific servlet class to invoke based on the servlet's configuration file, and passes the request object, the response object, to it.
4) The servlet knows who the client is using through the request object, what the customer's request information is, and some other information. When the servlet finishes processing the request, it puts the information to be returned into the response object and returns it to the client.
5) Once the servlet has finished processing the request, the Web container refreshes the response and returns control to the Web server.
Web-inf very important documents, indispensable, Lib put web pages need to use Java package, etc.;
Summarize:
HTTP is a set of rules for computers to communicate in a network
The HTTP request contains the request line, the request header, the blank line, and the message body
The HTTP response contains a status line, a response header, a blank line, and a message body
Web server has a flaw
CGI programs consume server resources severely, and servlets can eliminate this flaw
The Web container provides an environment for application components that are in the container
A Web application includes configuration files, static files, JSPs, class files, and packages
Tomcat is both an excellent jsp/servlet container and an HTTP server
Server.xml and Web. Xml are the main configuration files for Tomcat
Welcome-file-list indicates which file the server uses when it receives a directory name instead of the URL of the file name;
The server starts reading the Web. xml file first;
Configuration of the Web. xml file:
<?xml version= "1.0" encoding= "UTF-8"? ><web-app xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns= "Http://java.sun.com/xml/ns/javaee" xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee/http Java.sun.com/xml/ns/javaee/web-app_2_5.xsd "id=" webapp_id "version=" 2.5 "><!--Registration-<servlet> <!- -Registered name (must be unique); generally named, the servlet name you wrote-- <servlet-name>TestHttpServlet</servlet-name> <!-- The full class name (package name + class name) of the servlet given the script (the purpose is to have the Web container use a reflection mechanism to create an instance of the servlet)- <servlet-class> com.lovo.servlet.testhttpservlet</servlet-class> </servlet> <!--mapping servlet paths -- <servlet-mapping> <!--name the registered servlet mappings (registration, name and map name)-- <servlet-name>testhttpservlet </servlet-name> <!--mapping path, named with class name-- <url-pattern>/one</url-pattern> </ Servlet-mapping></web-app>
Java Web (2)