This is not original, from
http://www.javaresearch.org/forum/thread.jsp?column=20&thread=2281. Because it is necessary to continue to study, write first.
1. The conversion of international documents.
ApplicationResources_ISO.properties establish a file, the application with the message written in, and then execute this command in dos, this will convert native2ascii -encoding gb2312 ApplicationResources_ISO.properties ApplicationResources.properties ISO coded ApplicationResources GB2312 encoding format to the And save to ApplicationResources.properties.native2ascii This tool is a stuff with JDK comes with, so if both setting it 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
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 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; 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;