Set request attribute range: request_scope_01.jsp
The code is as follows: |
Copy code |
<% @ Page language = "java" contentType = "text/html" pageEncoding = "GBK" %> <% @ Page import = "java. util. *" %> <Html> <Head> <Title> Test </title> </Head> <Body> <% Request. setAttribute ("name", "James "); Request. setAttribute ("birthday", new Date ()); %> <Jsp: forward page = "request_scope_02.jsp"/> // if changed to a hyperlink, the request attribute cannot be obtained. </Body> </Html> Page after jump: request_scope_02.jsp <% @ Page language = "java" contentType = "text/html" pageEncoding = "GBK" %> <% @ Page import = "java. util. *" %> <Html> <Head> <Title> Test </title> </Head> <Body> <% String name = (String) request. getAttribute ("name "); Date birthday = (Date) request. getAttribute ("birthday "); %> <H1> <% = name %> <H2> <% = birthday %> </Body> </Html> |
Request object
The request information of the client is encapsulated in the request object, so that the client can understand the customer's requirements and then respond. It is an instance of the HttpServletRequest class.
Serial number method description
1 object getAttribute (String name) returns the attribute value of the specified attribute
2 Enumeration getAttributeNames () returns the Enumeration of all available attribute names
3 String getCharacterEncoding () returns the character encoding method
4 int getContentLength () returns the length of the request body (in bytes)
5 String getContentType () get the MIME type of the request body
6. ServletInputStream getInputStream () obtains the binary stream of a row in the request body.
7 String getParameter (String name) returns the parameter value of the specified name parameter.
8 Enumeration getParameterNames () returns the Enumeration of available parameter names
9 String [] getParameterValues (String name) returns an array containing all values of the parameter name
10 String getProtocol () returns the protocol type and version number of the request.
11 String getScheme () returns the scheduler name used for the request, such as http. https and ftp.
12 String getServerName () returns the server host name that receives the request
13 int getServerPort () returns the port number used by the server to accept the request.
14 BufferedReader getReader () returns the decoded request body
15 String getRemoteAddr () returns the IP address of the client sending the request.
16 String getRemoteHost () returns the client host name that sent this request
17 void setAttribute (String key, Object obj) set the attribute value
18 String getRealPath (String path) returns the actual path of a virtual path.