HttpServletRequest and HttpServletResponse detailed

Source: Internet
Author: User

Recently due to the re-encapsulation of CAS-related jar packages, I want to do as much as possible 0 configuration, and this process a lot to make

Use HttpServletRequest, now tidy up as follows, for later inspection. (The table is copied from other places, the layout is a bit of slag, paid to see it.) )

There are very many classes and interfaces related to the request response, and the following table is the primary class and interface related to the request and interface.

Main classes and interfaces related to requests and interfaces

Method

Description

ServletInputStream

Input stream of the servlet

Servletoutputstream

Output stream of the servlet

ServletRequest

Represents an interface requested by a servlet

Servletresponse

An interface representing the servlet response

Servletrequestwrapper

This class implements the ServletRequest interface

Servletresponsewrapper

This class implements the Servletresponse interface

HttpServletRequest

Inherits the ServletRequest interface, which represents the HTTP request

HttpServletResponse

Inherits the Servletresponse interface, which represents 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 get the name delivered by the client, the server-side hostname and IP address that generated the request and receives the request, as well as information such 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 name collection 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 value of the parameter in the request, which is specified by name

Getcharacterencoding ()

Returns the character encoding of the request

Getcontentlength ()

Returns the effective length of the request body

getInputStream ()

Gets the data in the requested input stream

GetMethod ()

Gets the way the request is sent, such as GET, post

Getparameternames ()

Gets the name of all parameters in the request

Getprotocol ()

Gets the protocol name used by the request

Getreader ()

Gets the data flow 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 accepted the request

Getserverpath ()

Gets the path of the requested file

2. HttpServletResponse

In a servlet, the HttpServletResponse interface is used when the server responds to a request from the client. You can use the setContentType () method to set the type of response. 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)

Encode 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 given name and date to the head of the response

SetHeader (String name,string value)

Sets the given name and value 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

HttpServletRequest and HttpServletResponse detailed

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.