Java HttpServletRequest and HttpServletResponse

Source: Internet
Author: User

This article is mainly about the Java HttpServletRequest and httpservletresponse details of the relevant information, the need for friends can participate in the test

Java HttpServletRequest and HttpServletResponse

Recently, the CAS-related jar package was re-encapsulated, so I wanted to do the 0 configuration as much as possible, and this process

Use HttpServletRequest, now tidy up as follows, so as to check later. (The form is made from somewhere else, and the typesetting slag is understood, paid.) )

Please be very much related to the type and interface, the following table is the main and the sum interface related to the interface.

The main and the interface of the sum interface

Servletresponsewrapper

td>

Method

Say

ServletInputStream

Servlet Input stream

Servletoutputstream

servlet output flow

SERVL Etrequest

Represents an interface for a servlet

Servletresponse

On behalf of the servlet An interface

Servletrequestwrapper

ServletRequest interface

The category Servletresponse interface

httpservletrequest

Continue to understand ServletRequest interface, HTTP request

HttpServletResponse

Serv Letresponse interface, representing HTTP please

Httpservletrequestwrapper

HttpServletRequest /p>

Httpservletresponsewrapper

HttpServletResponse The fact that

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 usually the numbers in the client's list. At the same time, the HttpServletRequest interface can be received by the client to send the name, you can obtain the product request and receive the request of the server terminal host name and IP address, but also to obtain the customer correct in the use of communication protocol and other information. The following table is a common method for interface HttpServletRequest.

Stating: The HttpServletRequest interface provides a good understanding of the methods.

Common methods of Interface HttpServletRequest

Method

Explain

Getattributenames ()

Returns a collection of all of the names of the previous requests

GetAttribute (String name)

Returns the value specified by name

GetCookies ()

Returns the cookie sent by client

GetSession ()

Returns the session with the client retransmitting, or returns NULL if no session is assigned to the client

GetSession (Boolean Create)

Return and client retransmitting session, create a session and return if no session is assigned to the client

GetParameter (String name)

To obtain the parameters of the request, the parameters are specified by name

Getparametervalues (String name)

Returns the value of the request, which is specified by name

Getcharacterencoding ()

Return to the request for the word Fu Yi password method

Getcontentlength ()

Returns the effective length of the request

getInputStream ()

Access to the numbers in the input of the request

GetMethod ()

To obtain the means of sending requests, such as GET, post

Getparameternames ()

Get the names of all the parameters in the request

Getprotocol ()

The name of the agreement used to obtain the request

Getreader ()

To obtain the flow of the request

GETREMOTEADDR ()

Access the client IP address

Getremotehost ()

Get the name of the client

getServerName ()

Returns the name of the server that accepted the request

Getserverpath ()

The path of the file to be obtained

2. HttpServletResponse

In a servlet, the HttpServletResponse interface is used when the server responds to a request from the client. The setContentType () method can be used to set the response type. To send character numbers, you can use Getwriter () to return an image. The following table is a common method for interface HttpServletResponse.

Common methods of Interface HttpServletResponse

Method

Explain

Addcookie (Cookie cookie)

Add the specified cookie to the pre-application

AddHeader (String name,string value)

Adds the specified name and value to the response's head message

Containsheader (String name)

Returns the value of an announcement, whether the affected head is set

Encodeurl (String URL)

The URL specified by the encoding

Senderror (int SC)

Sends a bug to the client using the specified state code

Sendredirect (String location)

Send a temporary response to the client

Setdateheader (String name,long date)

Set the name and date of the response to the head

SetHeader (String name,string value)

Set the name and value of the given head

SetStatus (int SC)

To the pre-settings

setContentType (String ContentType)

The MIME type of the settings

Thanks for reading, I hope to help the big guy, thank you for the support of this site!

From:http://www.15jb.net/java-httpservletrequest%e5%92%8chttpservletresponse%e8%a9%b3%e8%a7%a3

Java HttpServletRequest and HttpServletResponse

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.