Garbled Chinese parameter values passed to actionform by JSP in SSH

Source: Internet
Author: User

I checked a lot on the Internet, it is roughly known that Java in the network transmission of the default use of ISO-8859-1 encoding to pass the value, so the server needs to be transcoded in order to display normally. It's very depressing. It's impossible to write transcoding code every time you get the parameter value.

If you want to use spring filters for implementation, you don't know how to write the results.

 

Later, you can use the request on the Internet. setcharacterencoding ("gb2312") specifies the encoding of the parameter value when obtaining it. In the action and actionform pilot test, it is found that adding this code to the reset () method in actionform can solve this problem.

 

Later, it was said that <% request. setcharacterencoding ("gb2312"); %> was added to the JSP, and a little experiment was conducted. I did not know why.

 

I still want to use the filter method to implement it and write less code, which is currently under research. You copied the code section to get it done:

Web. xml

<Filter>
<Filter-Name> spring character encoding filter </filter-Name>
<Filter-class> org. springframework. Web. Filter. characterencodingfilter </filter-class>
<Init-param>
<Param-Name> encoding </param-Name>
<Param-value> gb2312 </param-value>
</Init-param>
</Filter>
<Filter-mapping>
<Filter-Name> spring character encoding filter </filter-Name>
<URL-pattern>/* </url-pattern>
</Filter-mapping>

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.