Jsp request usage

Source: Internet
Author: User
Tags port number

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.

Related Article

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.