Struts Chinese Solution

xiaoxiao2021-03-06  107

http://www.javaresearch.org/forum/thread.jsp?column=20&thread=2281&start=0&msRange=151. ApplicationResources.properties support the establishment of a Chinese ApplicationResources_ISO.properties file, the application with the message written in, then execute this command in dos, this will convert native2ascii -encoding gb2312 ApplicationResources_ISO.properties ApplicationResources.properties ISO-coded into ApplicationResources GB2312 encoding format, and at the same time to save ApplicationResources.properties.native2ascii this tool comes with a jdk East East, so if the PATH is set correctly, you can run directly, you can find him under $ java_home $ / bin. 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 When developing JSP, write <% @ Page ContentType = "TEXT / HTML; CHARSET = GB2312 "%>, set the character set to GB2312. 2. Make database operations support Chinese. Database Operation Support Chinese has always made me more headache, but I would like to recommend www.chinaxp.org for the good understanding, this website is developed with the Struts framework, and open source, download the source code, find it. Ok, read some source code, did not find any special character set conversion, very wonderful, accidentally saw that the upstairs message knows that the servlet can set the character conversion. Chinaxp.org is doing this.

Plus set character encoding com.huahang.tj.struts.Filters.SetCharacterencodingfilter Encoding gb2312 ignore True set character encoding action This will involve a bean, the source code is as follows: / * * XP forum * * Copyright (c) 2002-2003 Redsoft group. All rights reserved. * * / Package com.huahang.tj.struts.Filters ; import javax.servlet *;. import java.io.IOException; / ** *

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

    *
  • encoding - The character encoding to be configured * for this request, either conditionally or unconditionally based on * the ignore initialization parameter This parameter * is required, so there is no default.. *
  • ignore - if set to "true", any character encoding * specified by the client is ignored, and the value returned by the * selectencoding () selectencoding () SELECTENCODING Code> Method is set. if set to "false, *

    SelectEncoding () is caled Only if the * client HAS NOT ALREADY Specified An Encoding. by Default, this * Parameter is set to "true". * * *

    Although this filter can be used unchanged, it is also easy to * subclass it and make the selectEncoding () method more * intelligent about what encoding to choose, based on characteristics of * the INCOMING Request (Such As the Values ​​of the Accept-language * and user-agent headers, or a value stashed in the current * user's session. * * @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;

    } / ** * 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;

转载请注明原文地址:https://www.9cbs.com/read-105156.html

New Post(0)