刚开始我在JSP页面用的是GBK的编码格式,由于之前的疏忽,没有和同事统一编码格式(同事用的是UTF-8的),之后,我把同事的JSP页面pageEncoding=""的值改为GBK的,但是保存不了。没办法只好把自己的JSP页面的改为UTF-8的,但是我发现我以前的样式不起作用了。而且,有的汉字用String str=new String(s.getBytes("iso-8859-1"),"utf-8");转码后仍然是乱码,我注意了尤其是那个"态"字,以前用GBK的时候还没有这个问题,请高手指点!!!!急急!!!!

解决方案 »

  1.   

    eclipse里 右键属性--properties--info ---Text file encoding 改成统一的
    还不行就查看单个文件 右键属性--properties--info ---Text file encoding 改成统一的为了方便改下这里的设置
    windows Preferences---MyEclipse--Editors--把JSP--JS--CSS格式统一
      

  2.   

    用这个试试
    package org.edu.filter;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;
    import javax.servlet.http.HttpServletRequest;/**
     * 解决乱码问题的过滤器类
     *
     * @author coombe
     */
    public class SetCharacterEncodingFilter implements Filter {
    /** 字符编码 */
    protected String encoding = null;
    /** 过滤器配置器,init初始化过滤器方法中使用它取得web.xml中的配置参数 */
    protected FilterConfig filterConfig = null; /**
     * 初始化过滤器方法
     * @param filterConfig FilterConfig对象,系统初始化本类的实例时调用该方法
     *  并传递它,用于读取web.xml中的配置参数。
     * @exception ServletException
     */
    public void init(FilterConfig filterConfig) throws ServletException {
    this.filterConfig = filterConfig;
    this.encoding = filterConfig.getInitParameter("encoding");
    } /**
     * Filter类的核心方法,过滤器的功能,在这个方法中
     * 
     * @param request 请求对象
     * @param response 相应对象
     * @param chain 过滤器链
     * 
     * @exception IOException, ServletException
     */
    public void doFilter(ServletRequest request, ServletResponse response,
    FilterChain chain) throws IOException, ServletException {

    if (request instanceof HttpServletRequest
    && "GET".equalsIgnoreCase(((HttpServletRequest) request)
    .getMethod())) {
    // 当请求是GET放式时使用UTF-8字符集
    request.setCharacterEncoding("UTF-8");
    } else {
    // 使用web.xml中设置的字符集
    request.setCharacterEncoding(encoding);
    }
    //把请求和响应传递给下一个Filter或者其他JSP/Servlet等资源
    chain.doFilter(request, response);
    }

    /**
     * 系统销毁本过滤器前调用本方法,执行清理操作
     * 将encoding和filterConfig属性删除,释放占用的系统资源
     */
    public void destroy() {
    this.encoding = null;
    this.filterConfig = null;
    }
    }
      

  3.   

    加过滤器不错,不过也不能解决所有的文件编码问题。
    最好是把所有文件统一成一种编码,而且最好是utf-8
      

  4.   

    spring2.0有个可以搞定这个问题的过滤器,这WEB.XML配一个搞定