Introduction to WEB Application:
WEB Application Name
Web-inf
Xml
The configuration file for the Web application
Lib
The dependency package used by the Web application
Classes
The compiled servlet
Meta-inf
The context information that holds the Web application, in line with the Java EE standard
WEB application can be placed directly under Tomcat's WebApp directory
You can also specify the configuration file to a different directory in the Server.xml file
HttpServlet:
Servlet is the meaning of server applet
Used to complete the processing of the response of the client request under the B/S architecture
Cross-platform, often run in multi-threaded mode
The Servlet API provides a unified programming interface for Servlets
Servlets are typically run in containers, and the life cycle of the servlet is managed by the container
Common servlet containers
Tomcat
Resin
Jetty
Httpservetl inherited Genericservlet.
The Genericservlet class is the ancestor class of all Servlets
HttpServlet Main methods
Request Processing Method: (7 requests corresponding to HTTP protocol respectively)
1, doget response GET request, commonly used
2, dopost response to post requests, commonly used
3. Doput for http1.1 Protocol
4. Dodelete for http1.1 Protocol
5. Dohead responds only to the header of the GET request.
6. Dooptions for http1.1 Protocol
7. Dotrace for http1.1 Protocol
Service method, when a servlet is requested to arrive at the method first, the method is then distributed to the appropriate processing method
Servlet life cycle
The whole life process:
Load servlet and instantiate new
Initialize Init
Processing Request Service Doget DoPost
Exit service Destroy ()
Note that the servlet instantiates only once
The Init method also executes only once
Servlets are not thread-safe
Cookies
Cookie: A text file saved to a client that is relevant to a specific customer
Cookies save data in the form of a "name-value" pair
Create Cookie:new Cookie (name,value)
You can use the Setxxx method of cookies to set some corresponding values
SetName (String name)/getname ()//Set name
SetValue (String value)/getvalue ()//Set Value
Setmaxage (int age)/getmaxage ()//Set the time to store in seconds
Use the HttpServletResponse Addcookie (Cookie) method to set it to the client
Use HttpServletRequest's GetCookies () method to read all cookies from the client and return a cookie array
Can write content to the client, only text content
Client can block server write, disable cookies
You can read only what you webapp write.
Cookies are divided into two types
belongs to Window/Subwindow (placed in memory)
belong to text (with life cycle)
A servlet/jsp set of cookies can be either under the same path or under a sub-path
Servlet/jsp read that the other paths could not be read to the
As an example:
The requested path is Http:localhost:8080/test/testcookie
Test: The virtual path in Project name Testcookie:web.xml is configured in mapping
We're adding a path to/testcookie/testcookie2 in mapping so we can access cookies,
If the path we requested is Http:localhost:8080/tt/test/testcookie
TT: The virtual path in Project name Test/testcookie:web.xml is configured in mapping
We're adding a path to/testcookie/testcookie2 in mapping so we don't have access to cookies,
Because a servlet/jsp cookie can be set under the same path or under a sub-path
Servlet/jsp read that the other paths could not be read to the
Web applicationservlet,cookie,session