Java httpservletrequest and HttpServletResponse detailed _java

Source: Internet
Author: User

Java HttpServletRequest and HttpServletResponse detailed

Most recently, because of the encapsulation of the CAS-related jar packs, you want to do as much as 0 configurations, and the process is a lot of

Use HttpServletRequest, now sorted as follows, for later reference. (The form is copied from other places, the layout is a little bit, paid to see it.) )

There are a number of classes and interfaces associated with the request response, and the following table is the primary class and interface related to the request and interface.

The main classes and interfaces related to requests and interfaces

Method

Description

ServletInputStream

The input stream of the servlet

Servletoutputstream

The output stream of the servlet

ServletRequest

An interface that represents a servlet request

Servletresponse

An interface that represents the servlet response

Servletrequestwrapper

This class implements the ServletRequest interface

Servletresponsewrapper

This class implements the Servletresponse interface

HttpServletRequest

Inherits the ServletRequest interface, representing the HTTP request

HttpServletResponse

Inherits the Servletresponse interface, representing the HTTP request

Httpservletrequestwrapper

The realization of HttpServletRequest

Httpservletresponsewrapper

The realization of HttpServletResponse

The most important of the classes and interfaces given above are the httpservletrequest and HttpServletResponse interfaces, which are described in detail below.

1. HttpServletRequest

The most common method for HttpServletRequest interfaces is to obtain the parameters in the request, which are typically data in the client form. At the same time, the HttpServletRequest interface can obtain the name that is sent by the client, or the server-side host name and IP address that generate the request and receive the request, as well as the communication protocol that the client is using. The following table is a common method for interface HttpServletRequest.

Description: The HttpServletRequest interface provides a number of methods.

Common methods of Interface HttpServletRequest

Method

Description

Getattributenames ()

Returns the collection of names for all properties of the current request

GetAttribute (String name)

Returns the property value specified by name

GetCookies ()

Returns the cookie sent by the client

GetSession ()

Returns the session associated with the client and returns NULL if no session is assigned to the client

GetSession (Boolean Create)

Returns the session associated with the client and, if no session is assigned to the client, creates a session and returns

GetParameter (String name)

Gets the parameter in the request, which is specified by name

Getparametervalues (String name)

Returns the parameter value in the request specified by name

Getcharacterencoding ()

Returns the character encoding of the request

Getcontentlength ()

Returns the valid length of the requested body

getInputStream ()

Gets the data in the requested input stream

GetMethod ()

Gets how the request was sent, such as GET, post

Getparameternames ()

Gets the names of all the parameters in the request

Getprotocol ()

Gets the protocol name used by the request

Getreader ()

Get the data stream of the request body

GETREMOTEADDR ()

Get the IP address of the client

Getremotehost ()

Get the name of the client

getServerName ()

Returns the name of the server that accepts the request

Getserverpath ()

Gets the path of the requested file

2. HttpServletResponse

In the servlet, the HttpServletResponse interface is used when the server responds to a request from the client. You can set the type of response using the setContentType () method. Send character data, you can use Getwriter () to return an object. The following table is a common method for interface HttpServletResponse.

Common methods of Interface HttpServletResponse

Method

Description

Addcookie (Cookie cookie)

Adds the specified cookie to the current response

AddHeader (String name,string value)

Adds the specified name and value to the header information of the response

Containsheader (String name)

Returns a Boolean value that determines whether the head of the response is set

Encodeurl (String URL)

Encoding the specified URL

Senderror (int SC)

Sends an error to the client using the specified status code

Sendredirect (String location)

Send a temporary response to the client

Setdateheader (String name,long date)

Sets the name and date given to the head of the response

SetHeader (String name,string value)

Sets the name and value given to the head of the response

SetStatus (int SC)

Set the status code for the current response

setContentType (String ContentType)

Set the MIME type of the response

Thank you for reading, I hope to help you, thank you for your support for this site!

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.