Server Component, taobao
1. servlet
1. servlet is a special java class running on the server. It can be used to receive data transmitted from pages. It can be processed by java programs or returned to browsers, it also refers to ServletAPI.
2. Main servlet tasks:
(1) read the explicit request data sent by the client (browser. Includes Html forms.
(2) read the implicit request data sent by the client (browser. Including Cookies and media types.
(3) process request data and generate results.
(4) Send explicit data to the client (browser) in various formats.
(5) Send implicit data to the client (browser), including setting Cookies and caching.
3. servlet lifecycle:
(1) init () method
It will be called when the Servlet is created for the first time. Generally, when a user calls the Servlet URL for the first time, the Servlet will be created.
However, when the server is started, you can specify that the Servlet is loaded.
When a user calls a servlet, each servlet instance will be created, and each user's request will generate a new thread at an appropriate time.
To the doGet () or doPost () method.
(2) service () method
Is the main method to execute the actual task. The Servlet container (Web Server) calls the service () method to process requests from the client and returns formatted responses to the client.
Each time the server receives a servlet Request, the server generates a new thread and calls the service.
The service () method is called by the container, and the service method calls doGet, doPost, doPut, and doDelete when appropriate.
Therefore, you do not need to do anything for the service () method, but rewrite doGet () or doPost () based on the request type from the client you receive ().
DoGet () and doPost () are the most common methods in each service request. The following are the features of these two methods.
(3) destroy () method
The destroy () method is called only once when the servlet lifecycle ends.
4. Read form parameters
GetParameterNames (): If you want to obtain a complete list of all parameters in the current request, call this method.
The GET method has a size limit: The request string can contain a maximum of 1024 characters.
Ii. filter
1. filter is a server component that uniformly intercepts and filters requests sent by the browser before they reach the Web resource or returns the response from the Web resource to the browser.
2. lifecycle:
(1) create an object:Executed during Web application loading-- Run only once: It indicates that the Filter is also run in a single instance with multiple threads.
(2) initialization operation: Execute immediately after the object is created -- only once
(3) intercept browser requests: Execute the doFilter () object-multiple executions
(4) Before the object is released: Perform the cleanup operation -- only once
3. ing method
(1) URL
Exact match: specify a specific url address in the URL-pattern tag without any wildcards, for example:/target. jsp
Fuzzy match: specify a url address with a wildcard in the URL-pattern tag.
<1> prefix match: prefix is determined before the URL address, followed by a wildcard, for example,/happy /*
<2> suffix matching: the URL address is determined after it. Wildcards are used before, for example, *. jsp and *. jpg.
Note: wildcards cannot be used between URLs. For example,/happy/*. jsp is not allowed.
(2) map Servlet
4. execution sequence of multiple filter chains
Execute in the order of FilterMapping
5. Common usage
(1) user name and password verification
(2) filter indecent characters: HttpServletRequestWrapper, modifier Mode
* In Java Web applications, many server component objects are created by server containers,
Specifically, we provide registration information for these server components, and then the container will detect and create objects through reflection. This is a idea of dependency injection,
However, this will cause a problem. We cannot modify their methods. inheritance will lead to poor migration of the program,
Therefore, we use the modifier mode to wrap the objects created by the original server container and modify some of its methods to achieve the expected results.
Not complete, to be continued.