request text study notes

1 Common APIs for request objects

1) Get the information related to the request header
*a)request.getHeader(String):String
b)request.getHeaders(String):Enumeration
c)getHeaderNames():Enumeration

*2 Get the value of the request parameter

2) Obtain the information related to the request body
a) request.getParameter(String):String
b)request.getParameterValues(String):String[]
Note: In the GET request mode, if the parameters are inconsistent and null is returned, a null pointer exception may occur
c) The BeanUtils framework can automatically set the String parameters to the JavaBean object
1) No need to pay attention to the type and number of parameters, but the parameter names must be consistent with the fields in the JavaBean
2) String->8 basic types are automatically converted, not 8 A basic type can register conversion equipment
3) String or String[] type parameters are automatically aware of the assembly

*3 request application

1)
Where does the anti-leech judging segment come from, that is, the referer request header

2) Collect form data
a) In the project, the parameters requested by the user, it is best to do the second judgment of null or empty string

3) Chinese garbled characters
a) Reasons for garbled characters in POST mode: The encoding method sent by the browser is inconsistent with the encoding method of the Request object
Solution: request.setCharacterEncoding("UTF-8), this method can only parse the garbled characters in the request body In addition, it is unable to solve
b) If the user submits by post, in the case of forwarding, it is still a post request, but in the case of redirection, it is a get request
c) If the user submits by get, in the forwarding and reloading In the case of orientation, it is all get requests
d) 405: The request itself is a get request, but the corresponding doGet() method is not provided in the servlet, and the post is similar

*4 Let's talk about the MVC design pattern again

1) If you strictly follow the MVC idea, the browser home page accesses the controller, and then the controller forwards it to the view
2) The resources located in the WEB-INF/ directory cannot be directly accessed by the client, but can only be forwarded by the server Enter
3) The request object can also be used for resource forwarding
request
.getRequestDispatcher("/WEB-INF/success.html")
.forward(request,response);
4) Verify Chinese by regular expression: [\u4E00-\uFA29] +
5) For redirection, the two Request domain objects before and after are different. If the value cannot be obtained, "null" will be returned, and no error will be reported.

5 request details

1) Forwarding is done through the forward(request, response) method of the RequestDispatcher object
2) The output before the forward() method, if it is output to the buffer and then forwarded to other servlets, the data in the original buffer is ignored
3) The output before the forward() method, if it is actually output to the browser, then forwarded to other servlets, and then forwarded to other servlet code is ignored
4) The output before the forward() method, if it is the setting of the response header, will be retained until In other servlets that are forwarded

*6 Difference between redirection and forwarding

1) Forwarding can only be relative to the current web application and cannot be forwarded to other web applications
Redirection can be rewritten to resources in other web applications other than the current web application
2) Forwarding/representing current web application
redirection/representing web server 3) When forwarding, the
browser address bar does not change
. When redirecting, the browser address bar changes
. 4) Forwarding is the internal behavior of the server. The browser does not know that
redirection is the common behavior of the browser and the server. Browsers must know
5) When forwarding, two servlets share request domain objects
When redirecting, two servlets share request domain objects exclusively.
6) Requests are ambiguous:
a) request object
b) domain object

7 include contains

1) When you need to use a servlet to include the same page output, similar to a function call

8 Session
1) The user outputs the URL address, effectively visits a certain website, a series of effective operations on the website, and then closes the entire process of the browser, called a session
2) The session mainly solves how the server saves the correspondence of each client. private information.
3) There are two main types of sessions:
a) Cookie technology [client technology]
b) Session technology

*9 Cookie

1) Cookie is the technology of the client
2) Each time a request is sent, the client will bring its own different cookies to the server. Once the server parses the cookie, it knows which client sent the information
3) A cookie only It can store one type of information
4) Update a cookie with a certain name, that is, write a cookie with the same name to the browser
5) The cookie must be set with a valid time. Automatic destruction, in professional terms,
the default validity period of a cookie ends when a valid session ends

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324527748&siteId=291194637