乱码解决

1.jsp页面设置

2.添加过滤器

3.修改struts.properties(即struts2核心包中的default.propeties)或struts.xml

4.在spring中配置(applicationContext.xml文件)

5.mysql中配置





1.jsp页面设置:<%@ page language="java" contentType="text/html; charset=gbk"%>

2.添加过滤器:

package com.autumn.filter;

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 EncodingFilter implements Filter
{
public void init(FilterConfig filterConfig)throws ServletException
{}
public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain)throws java.io.IOException,ServletException
{
  try
  {
  
   request.setCharacterEncoding("gbk") ;
   response.setCharacterEncoding("gbk") ;
  }
  catch (Exception e)
  {
   e.printStackTrace() ;
  }
  chain.doFilter(request,response) ;
}
public void destroy()
{}
}






3.修改struts.properties或struts.xml:

(1)struts.properties中修改

     struts.locale=zh_CN
     struts.i18n.encoding=gbk

(2)struts.xml中添加:

    <constant name="struts.i18n.encoding" value="GBK"/>

4.在spring中配置

(1)数据源

<property name="url"
   value="jdbc:mysql://localhost:3306/ordermanagement?useUnicode=true&amp;characterEncoding=gbk">
  </property>

(2)hibernate属性

<prop key="hibernate.connection.useUnicode">true</prop>
<prop key="hibernate.connection.characterEncoding">gbk</prop>

5.mysql中配置

../mysql/my.ini中修改两处的字符编码,均改为gbk

你可能感兴趣的:(乱码)