I learned Struts to encounter Chinese problems, study all day, hive online, I will share it, share it! If you can correct it, thank you!
Struts resource file Chinese character set problem
Native2ASCII -Encoding GBK f: /mystruts/src/mystruts/applicationresources.properties f: /mystruts/src/mystruts/applicationResources_zh_cn.properties converts the original resource file into GBK code. And add the following code (red part) in the web.xml file:
XML Version = "1.0" encoding = "GBK"?>
init-param>
init-param>
init-param>
servlet>
servlet-maping>
init-param>
filter>
filter-mapping>
filter-mapping>
filter>
filter-mapping>
filter-mapping> ->
taglib>
taglib>
taglib>
taglib>
web-app>
Struts Chinese problem
Solution 1: (Not implemented)
JAKARTA-STRUTS-
1.0.2
-SRC / SRC / Share / ORG / Apache / Struts / Util / PropertyMessageresources.java
Row on page 289: Messages.Put (MesS.GEy (key), prOPs.getProperty (key)); changed to the following code:
String sprops = props.getproperty (key);
Try
{
Sprops = new string (Sprops.getbytes ("ISO-8859-1"), "GBK");
}
Catch (Exception E)
{
E.PrintStackTrace ();
}
Messages.Put (MessageKey (LocaleKey, Key), Sprops;
Replace the PropertyMessageResources class in the original struts.jar after compile.
Workaround 2:
Was added in two classes filters.RequestDumperFilter engineering, filters.SetCharacterEncodingFilter (C: / Program Files / Apache Software Foundation / Tomcat 5.0 / webapps / jsp-examples / WEB-INF / classes / filters), to modify the code WEB.XML (red Part below is as follows:
XML Version = "1.0" encoding = "GBK"?>
init-param>
init-param>
init-param>
servlet>
servlet-maping>
init-param>
init-param>
filter>
filter-mapping>
taglib>
taglib>
taglib>
taglib>
web-app>
Workaround 3:
For processing Struts framework Chinese encoding problems, there are many ways, here we try to inherit the ActionServlet class and override the Process method, and set request coding in subclass processing methods. Thereby, the ActionServlet is displayed to play the traits of the front-end Controller.
First, click Select JBuilder Main Menu File | New Classes to prepare a new class. And inherit from org.apache.struts.Action.ActionServlet
And change the preset class name to the GBKActionServlet. The program code is generated after pressing the OK button. Click to select JBuilder main menu Wizards | Override Methods ... Activate Coverage Elf, Coverage Wizard automatically lists all methods of overworked by parent class ActionServlet. You can select the Process (HTTPServletResponse, and press the OK button after the Available Methods clear order. At this point, we can modify the override Process method code as follows: Request.SetCharacterencoding ("GBK"); super.process (request, response);
The first line program code sets the parameter request from Process to GBK encoding, and the rest of the behavior is the same parent class. Next we will modify the web.xml deployment description file to specify the entry point of the servlet, first click to select Web.xml in the upper left project pane. At this time, the upper left side structure pane will appear a tree structure in the XML tag in Web.xml. You can click on the Action project in Select Servlets.
You can press the servlet class project Right Party [...] button to select the new input point replacement preset ActionServlet, which is the Util. GBkActionServlet we wrote. If you are very familiar with the web.xml structure, you can directly click on the Sources page in the Select Content Pate, and the contents of the
XML Version = "1.0" encoding = "UTF-8"?>
filter>
init-param>
filter>
filter-mapping>
filter-mapping>
init-param>
init-param>
init-param>
servlet>
servlet-maping>
taglib>
taglib>
taglib>
taglib>
web-app>