1. ApplicationResources.properties support the establishment of a Chinese ApplicationResources_ISO.properties file, the application with the message written in, and then execute this command in dos, native2ascii -encoding gb2312 ApplicationResources_ISO.properties ApplicationResources.properties this will be the ISO code ApplicationResources converted into GB2312 encoded format, saving to ApplicationResources.properties.native2ascii This tool is a stuff with JDK, so if both set it correctly, you can run directly, you can be under $ java_home $ / bin find him. The conversion is similar to this like ISO format: tj.type = commodity vehicle type GB2312 format: tj.type = / u5546 / u54c1 / u8f66 / u7c7b / u578b then set this resource file in Struts-Config.xml
Plus Filter that sets the character encoding to be used in parsing the * incoming request, either unconditionally or only if the client did not * specify a Character Encoding. Configuration of this filter is based on * The folowing initialization parameters: p> * *
ignore code> initialization parameter This parameter * is required, so there is no default.. li> *
selectencoding ()
selectencoding ()
SELECTENCODING Code> Method is set. if set to "false, *
SelectEncoding () code> is caled Only strong> if the * client HAS NOT ALREADY Specified An Encoding. by Default, this * Parameter is set to "true". li> * ul> * * Although this filter can be used unchanged, it is also easy to * subclass it and make the } / ** * Select and set (if specified) the character encoding to be used to * interpret request parameters for this request. * * @Param request The servlet request we are processing * @param result The servlet response we are creating * @ param chain The filter chain we are processing * * @exception IOException if an input / output error occurs * @exception ServletException if a servlet error occurs * / public void doFilter (ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {/ / Conditionally select and set the character encoding to be used if (ignore || (request.getCharacterEncoding () == null)) {String encoding = selectEncoding (request); if (! encoding = null) request.setCharacterEncoding (encoding); } // Pass Control on to the next filter chain.dofilter (request, response);} / ** * place . This filter into service * * @param filterConfig The filter configuration object * / public void init (FilterConfig filterConfig) throws ServletException {this.filterConfig = filterConfig; this.encoding = filterConfig.getInitParameter ( "encoding"); String value = filterConfig. GetInitParameter ("ignore"); if (value == null) this.Ignore = true; Else IF (Value.equalsignoreCase ("true") this.Ignore = true; Else IF (Value.Equalsignorecase ("YES"))) ignore = true; else this.ignore = false; } // ----------------------------------------------------------------------------------------------------------------------------------------------------- ------- Protected Methods / ** * Select an appropriate character encoding to be used, based on the * characteristics of the current request and / or filter initialization * parameters. If no character encoding should be set, return * < code> null code>. * * The default implementation unconditionally returns the value configured * by the encoding strong> initialization parameter for this * filter. * * @param request The servlet request we are processing * / Protected string selectEncoding (THIS.Encoding);}} // EOC, after this, you can receive GB2312 encoded data directly from the Form, and naturally GB2312 is naturally GB2312. But this seems to be a container in servlet 2.2 or more, I solved the Chinese problem in Struts, and I haven't found new problems yet. My environment is Windows2000 Professional, Tomcat 4.04, Struts1.1B2 Detailed address http://www.javaresearch.org/forum/thread.jsp?column=20&thread=2281 selectEncoding () code> method more * intelligent about what encoding to choose, based on characteristics of * the INCOMING Request (Such As the Values of the
Accept-language code> * and
user-agent code> headers, or a value stashed in the current * user's session. p> * * @Author John wong * @version $ ID: setcharacterencodingfilter.java, v 1.1 2002/04/10 13:59:27 Johnwong Exp $ * / Public class setcharacterencodingfilter imports filter {// ------------------------------------------ ----------- Instance variables / ** * The default character encoding to set for reviews That pass throgh * this filter. * / Protected String Encoding = null; / ** * The filter configuration object we are associated with If this value * is null, this filter instance is not currently configured * / protected FilterConfig filterConfig = null;.. / ** * Should a character encoding specified by the client BE IGNORED? * / protected boilean ignore = true; // ------------------------------------- -------------------- Public Methods / ** * Take this filter out of service. * / Public void destroy () {this.encoding = null; this.filterconfig = NULL;