Chinese garbled characters in struts 2.0

Source: Internet
Author: User
Tags i18n

1. Add the following content to struts. xml:

<Constant name = "struts. i18n. encoding" value = "gb18030"/>




2. Solve Chinese garbled characters in struts 2.0. Configure the following in the Struts. properties file.





Struts. i18n. encoding is used to set the default encoding for Web applications, while gb2312 specifies the default encoding.

This method solves the problem of Chinese garbled characters after the form is submitted. In this case, the method attribute value of the form must be post. If the form implemented by the form tag in struts 2.0 is used, the method attribute can be omitted. The default value is post; if the form is implemented through the form identification of the original HTML language, you need to set the method attribute and assign the value to post.




If the value of a parameter passed by a hyperlink is a Chinese character, the following transcoding operation must be performed after the parameter value is obtained in the Action Service controller. Otherwise, the obtained value is garbled.

String sqlvalue = request. getparameter ("sqlvalue"); // obtain the parameter sqlvalue = new string (sqlvalue. getbytes ("ISO-8859-1"), "gb2312"); // perform transcoding operations

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: 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.