JSP built-in object request and response

Source: Internet
Author: User
Tags send cookies

1.request objects are primarily used to process client requests

Common methods for Request objects

A. String Request.getparameter (string name) gets the value values of the component based on the component name value of the page form (note: If the requested component name does not exist, return NULL if the request component's value Value is null returns "" empty string)

Two. String request.getparametervalues (string name) gets a set of component value values with the same name (the content of the checkbox multi-select button is primarily obtained)

Three. Request.getrequestdispatcher (String path) returns an object and then invokes the. Forward (Request,response) with the object; for forwarding requests

Four. Request.setcharacterencoding (String CharSet) specifies the encoding of each request and is set before calling the Request.getparameter () method to solve the Chinese garbled problem

Five. Request.getcookie () Read all cookie content

2.response objects are primarily used for server-to-client response

Common methods for response objects

I. Response.sendredirect (String path) request to relocate to a new URL

Two. Response.addcookie (cookie cookie) to send cookies to the browser


3. Chinese garbled problem

I. Using the fourth method of request to set if Request.setcharacterencoding ("UTF-8") is encoded as utf-8 then the values of pageencoding and charset in the page directive will be consistent with Utf-8.

Two. String Name=request.getparameter ("username");

Name=new String (name.getbytes ("ios-5589-1"), "Utf-8"); The name string is parsed into a byte array with ios-5589-1 encoding, and the byte array is reconstructed with a new string by using the Utf-8 encoding with the new string () method.

Three. Add the Uriencoding attribute value in the Tomcat directory structure conf/server.xml file <connector> element to: Utf-8 (note: Use mode three is not recommended.) )


JSP built-in object request and response

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.