Chinese garbled problem solving

2010-04-05  来源:本站原创  分类:Java  人气:186 

Taken from "Eclipse Development Study Notes" - Lin Jian Su, Meng Kangjian edited

First of all, in the Tomcat "webapps \ servlets-examples \ WEB-INF \ class \ filters" directory SetCharacter EncodingFilter.class copied to util package. Then, in the web project profile web.xmlde <web-app>, add the following code:

<filter>
                <filter-name>setCharacterEncodingFilter</filter-name>
                <filter-class>util.SetCharacterEncodingFilter</filter-class>
                <init-param>
                        <param-name>encoding</param-name>
                        <param-value>UTF-8</param-value>
                </init-param>
        </filter>
        <filter-mapping>
                <filter-name>setCharacterEncodingFilter</filter-name>
                <url-pattern>/*</url-pattern>
        </filter-mapping>

Attached SetCharacterEncodingFilter code for reference:

package util;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class SetCharacterEncodingFilter implements Filter {

        protected String encoding = null;

        protected FilterConfig filterConfig = null;

        protected boolean ignore = true;

        public void destroy() {

                this.encoding = null;
                this.filterConfig = null;

        }

        public void doFilter(ServletRequest request, ServletResponse response,
                        FilterChain chain) throws IOException, ServletException {

                if (ignore || (request.getCharacterEncoding() == null)) {
                        String encoding = selectEncoding(request);
                        if (encoding != null)
                                request.setCharacterEncoding(encoding);
                }
                chain.doFilter(request, response);
        }

        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"))
                        this.ignore = true;
                else
                        this.ignore = false;

        }

        protected String selectEncoding(ServletRequest request) {

                return (this.encoding);

        }
}
相关文章
  • Toad8 Chinese garbled problem solving 2010-11-11

    In the database server character set is AL32UTF8, we have to think about and deal with what Windows XP environment Toad tool shows garbled characters in question. 1. In view of "character set] [" Client Terminal Character Set "," NLS_L

  • Java / JSP Chinese garbled problem solving experience 2010-11-25

    Since the exposure to Java and JSP has to constantly deal with Java's garbage problem in Chinese, and now finally been completely resolved, we now experience and share solutions. One, Java the Chinese origin of the problem Java class files and the ke

  • Eclipse.Properties Chinese garbled problem solving 2011-06-01

    Jira recently with Eclipse plug-in development, has been the Chinese garbled problems plague. After exploring, there are powerful search with google to find a bunch of relevant information, and finally put this issue is resolved. Now this process of

  • jfreechart histogram, Chinese garbled problem solving (transfer) 2011-05-08

    Original: http://hi.baidu.com/lynsahuang/blog/item/313c6fd0f6221eda562c84ab.html Added in the original Chinese garbled on the basis of solution to the problem In our programming if we want the results displayed as graphical form, to not be separated

  • SSH-centos Chinese garbled problem solving 2011-03-03

    centos5.2 configuration is complete, normal to display Chinese, view found support for utf-8 character set. The putty and ssh secure shell connection found garbage, mainly for the implementation of vim garbled, su command garbled. Use $ locale comman

  • Chinese garbled problem solving PLSQL 2011-07-20

    Installation instantclient10.2 can use string to connect to the database. Need to create a dsn, extracted directly in the windows, and then added to the directory in the path environment variable can be. Download PL / SQL Developer, unzip, Enter the

  • Secure CRT Chinese garbled problem solving 2011-05-18

    Ssh 2.6 kernel's default encoding is UTF 8, will also change securecrt encoding UTF 8, ah, problem solved. Modification method: Options -> Session Options -> Apperance -> Fonts -> Character. utf8 1, Emulation Terminal choice is Linux, and sele

  • Turn: git windows directory Chinese garbled problem solving 2010-01-18

    Git version of Windows Msysgit support of the Chinese is not good enough when used, the following three cases of Chinese garbage: 1.ls not display Chinese catalog solution: git / git-completion.bash add a line: alias ls = 'ls - show-control-chars - c

  • ubuntu pdf Chinese garbled problem solving 2011-08-09

    Specific steps: First, install a thing, seems to be fonts Oh? sudo apt-get install poppler-data Second, change the font configuration file sudo gedit / etc/fonts/conf.d/69-language-selector-zh-cn.conf I only modified the red font is WenQuanYi Zen Hei

  • Chinese garbled problem solving 2010-04-05

    Taken from "Eclipse Development Study Notes" - Lin Jian Su, Meng Kangjian edited First of all, in the Tomcat "webapps \ servlets-examples \ WEB-INF \ class \ filters" directory SetCharacter EncodingFilter.class copied to util package.

  • php generated excel class (Chinese garbled problem solving, multi-workbook) data sub-volume technology 2010-09-12

    <?php /** * @desc excel Interface * @author mengdejun */ interface IExcel { // Export excel public function export($fileName="excel"); // Add Row public function addRow(array $array,$sheet="sheet1"); // Add header public function ad

  • jsp Chinese garbage problem solving 2010-05-30

    jsp Chinese garbage problem solving Method 1. JSP page displays garbled display the following page (display.jsp) The garbled :<html><head><title>JSP Chinese language processing </title><meta http-equiv="Content-Type" c

  • The Chinese garbage problem solving Msysgit 2010-05-31

    The Chinese garbage problem solving Msysgit Git for Windows version Msysgit support for Chinese is not good enough when used, the following three conditions in Chinese garbled: 1.ls not display Chinese catalog solution: the git \ etc \ git-completion

  • Chinese garbage problem solving netbeans 2010-06-28

    Chinese garbage problem solving netbeans After installing netbeans, menu in Chinese is no problem, the local tag and html content in Chinese for the distortion. Are: Solution is to modify the netbeans / etc / netbeans.conf file, add: -J-Dfile.encodin

  • Chinese garbage problem solving Msysgit 2010-12-07

    Chinese garbage problem solving Msysgit (rpm) The Windows version of Msysgit Git support for Chinese is not good enough when used, will appear garbled in Chinese three cases: ls can not display Chinese directory. The solution: the git / etc / git-com

  • Achieved by DhtmlXtree display, modify, add, delete, move functions to achieve a tree, iframe single slider shown in the tree nodes contained in the iframe is too long for Chinese content problem solving 2010-10-12

    Achieved by DhtmlXtree display, modify, add, delete, move functions to achieve a tree, iframe single slider shown in the tree nodes contained in the iframe is too long for Chinese content problem solving 1, the data in the database composed of a stri

  • Some garbled problem solving 2009-06-11

    Recently hosted an information release system, met a few garbled problems, engage in the head are larger. Eventually try to go to a different transcoding only then solve the problem, so the problem record. JSP page is submitted to the Servlet for the

  • "Chinese garbled" problem of the Linux system. Vi.SQLPlus.PuTTY (change) 2010-06-06

    [Description] problem 1.Linux system with Chinese content of the file name garbled; 2. Using the vi editor for the garbled view the Chinese contents; 3.sqlplus access to the database to view the content of the garbage in Chinese; 4.putty appear garbl

  • Difference between MySQL character set GBK.GB2312.UTF8 MYSQL Chinese garbage problem solving 2010-09-30

    MySQL character sets involved in several character-set-server/default-character-set: server character set, used by default. character-set-database: the database character set. character-set-table: database table character set. Increase in priority or

  • mysql default encoding set gbk, to solve the query dos Chinese garbled problem 2010-12-06

    We are using the dos window command line login. Check out the results available in Chinese, the problem will be garbled. Solution to this problem is to set the mysql default encoding. MySQL's default encoding is Latin1, does not support Chinese, so h