Using filters to solve Chinese garbled characters

Source: Internet
Author: User

    1. Review of Knowledge points

(1) request.setcharacterencoding ()

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/57/90/wKiom1SeFIrSutgqAAFYi3JKrbs805.jpg "title=" Request.png "alt=" Wkiom1sefirsutgqaafyi3jkrbs805.jpg "/>

The method is to set the character encoding of the request body, which tells Java what format to use for decoding.

This method is only valid for post requests because the parameters of the post request are in the request body.

(2) response.setcharacterencoding () 650) this.width=650; "Src=" http://s3.51cto.com/wyfs02/M02/57/8E/ Wkiol1sef5-dtneiaalsw7ypk4e444.jpg "title=" Response.png "alt=" Wkiol1sef5-dtneiaalsw7ypk4e444.jpg "/>

Set the character encoding of the response


(3) Uriencoding

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/57/8E/wKioL1SeGBuA9ryRAACffBi8IbE110.jpg "title=" Connector.png "alt=" Wkiol1segbua9ryraacffbi8ibe110.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/57/8E/wKioL1SeGHvDqpZHAACB3OGIU5A704.jpg "title="    Sdf.png "alt=" Wkiol1seghvdqpzhaacb3ogiu5a704.jpg "/> The uriencoding attribute of the connector element in the Server.xml file specifies the character encoding of the decoded URI, which by default is Iso-8859-1

When a GET request is requested, the request parameter is appended to the URL. Therefore, the encoding specified here is valid for the GET request.


2. Actual combat

(1) Set uriencoding to UTF-8

(2) Configure filters (use spring's own filters here)

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/57/91/wKiom1SeGZGwvHCWAAJU7g00YHU574.jpg "title=" Web.png "alt=" Wkiom1segzgwvhcwaaju7g00yhu574.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/57/91/wKiom1SeGamAZPBHAAUuAHTe1lY907.jpg "title=" Spring.png "alt=" Wkiom1segamazpbhaauuahte1ly907.jpg "/>

At this point, all the Get and POST request parameters are unified using UTF-8 decoding, and all the response codes are UTF-8.

This article is from the "ten-li Rice flower" blog, please be sure to keep this source http://5880861.blog.51cto.com/5870861/1596458

Using filters to solve Chinese garbled characters

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.