1. To set the character encoding for struts, add the following code to the Struts.xml:
<constant name= "struts.i18n.encoding" value= "GBK"/>
Or find the default configuration file for struts, located in Struts2-core-2.3.16.3.jar org.apache.struts2 the default.properties file in the package. Modify the following configuration:
# # # This can is used to set your default locale and encoding scheme# STRUTS.LOCALE=EN_USSTRUTS.I18N.ENCODING=GBK
2. Set the JSP page character encoding:
<%@ page language= "java" contenttype= "text/html; CHARSET=GBK " pageencoding=" GBK "%>
3. If the above method does not solve the garbled, it is possible that Tomcat will accept the GET request by default using ISO-8859-1 encoding, need to find the Web. xml file under Apache-tomcat-6.0.39/conf, modify the following code:
<connector uriencoding= "GBK" connectiontimeout= "20000" port= "8080" protocol= "http/1.1" redirectport= "8443"/>
So 3 steps can solve most of the Stuts2 Chinese garbled problem, such as can not be solved, only manually modified code with Java, the method is as follows:
public static string Changeencoding (string s, String oldencoding, String newencoding) {string result = null;try {result = New String (S.getbytes (oldencoding), newencoding);} catch (Unsupportedencodingexception e) {e.printstacktrace ();} return result;}
[Java Web] Struts2 solve Chinese garbled problem