My Way of Learning _ 32nd Chapter _httpservletrequest

Source: Internet
Author: User

HttpServletRequest

Get information about the request line:

return value: String GetMethod () Request method

return value: String Getrequesturi () Request destination

return value: String Getprotocol () use protocol

Get information about the request header:

return value: String GetHeader (string name)
A key value for a request header that returns the value of a request header

return value: Stringgetheadernames (String name)

Gets the name of all request headers, encapsulated in the enumeration collection

Gets the resulting object, there is a method, Hasmoreelement () to determine whether the next element in the collection, Nextelement () to get the next element (the name of the request header)

Obtaining information about the request body (important)


return value: Stringgetparameter (String name)

return value: String[]getparametervalues (String name)

Gets the submitted content in a name that is worth a parameter

return value: Enumeration<string> getparameternames ()

return value: Map<string,string[]>getparametermap ()

Gets all the parameters in the request body, encapsulates the parameters into the map collection, where key is the name of the commit, and the string data is the value.

Note that the previous two methods are for programmers, followed by two methods for the framework (common Code) (Beanutils tool Class)


Set character sets

Setcharacterencoding ("UTF-8"): Only solve the problem of Chinese garbled characters in the post mode submitted parameters

Internal forwarding

Getrequestdispatcher ("Webpath"). Forward (REQ,RESP)
Note: The destination page jumps from inside the server to the past, so no new requests and responses are generated, so the catalog page uses the same request and response object as the current page. So
To enable the use of the request domain to pass data between even pages.

Domain object: The life cycle is generated when the request arrives at the server and is destroyed when the response is sent back to the browser.


The difference between redirection and internal forwarding:

Redirect: The browser sends the request to the server, the server sends back the instruction, asks the browser to send the request to the specified URL.
In fact, the browser sent two requests, so the address bar of the browser is the address of the second page
So when you press F5 to refresh the page, the request submitted to the second page
Because the second page is a new request, you want to pass data between the first page and the second page, and you cannot use the request domain.

Internal forwarding: By the browser to send a request to the server, the server inside the request to the second page, the second page run results, the final page results
Response to the browser. So the address bar in the browser does not change, or the address of the first page, but the page content displayed in the browser is the content of the second page.
Because the first and second pages use the request and response objects that access the first page, you can use the request domain when passing data.

Priority use of internal forwarding is used only if the first page is a form submission, and the second page needs to be refreshed. (When you need to display one-time data,
Therefore, the request domain must be used to pass data between two pages, so it must be forwarded internally.

Beanutils Tool Class

Popuplate (Object Bean, MAP)

Date conversion: 1, creating a Date Converter Object 2. Set the format of the Converter 3. Register the converter (tell the Beanutils tool to use this converter when converting a string to what type)


My Way of Learning _ 32nd Chapter _httpservletrequest

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.