SSH框架下中文乱码问题

1、连接数据库的时候

jdbc.properties:jdbc:mysql://localhost:3306/myproject?useUnicode=true&characterEncoding=utf8
applicationContext.xml: jdbc:mysql://localhost:3306/myproject?useUnicode=true&characterEncoding=utf8

 

 

 

2、设置mysql字符集

 show variables like'character_set_%';

把显示的character_set_**全都设置成utf8,即是:set character_set_serve='utf8'

 show variables like '%collation%';

把显示的都设置成为如下:set collation_server='utf8_general_ci'

 

 

3、修改mysql配置文件my.ini

default-character-set=utf8

 

 

4、建一个过滤类

package com.broadengate.crm.filter;

import java.io.IOException;

importjavax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class CharacterEncodingFilter implements Filter{

     public void destroy() {
     }

   public void doFilter(ServletRequest request, ServletResponse response,
                            FilterChain chain) throws IOException, ServletException {
                              request.setCharacterEncoding("utf-8"); 
                              chain.doFilter(request, response);  
    }

    public void init(FilterConfig arg0)throws ServletException {
  
    }

}

web.xml配置加 
 
   encodefilter 
      com.broadengate.crm.filter.CharacterEncodingFilter
  

   
          encodefilter
          /*
  

 

 

5、修改tomcat中的配置文件server.xml

                      connectionTimeout="20000"
              redirectPort="8443" />

        改为

                     connectionTimeout="20000"
              redirectPort="8443" URIEncoding="UTF-8"/>

 

6、在web.xml配置spring过滤器

   char

   org.springframework.web.filter.CharacterEncodingFilter

    

        encoding

        UTF-8

    

    char

    /*

你可能感兴趣的:(SSH框架下中文乱码问题)