| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1013 人关注过本帖
标题:中问乱码问题(谁能注释一下这段代码)
只看楼主 加入收藏
新手上路了
Rank: 1
等 级:新手上路
威 望:2
帖 子:107
专家分:0
注 册:2008-3-27
结帖率:100%
收藏
 问题点数:0 回复次数:2 
中问乱码问题(谁能注释一下这段代码)
package com.filters;

import
import javax.servlet.*;

//中文过滤器
public class SetCharacterEncodingFilter
    implements Filter
{

    public SetCharacterEncodingFilter()
    {
        encoding = null;
        filterConfig = null;
        ignore = true;
    }

    public void destroy()
    {
        encoding = null;
        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;
        encoding = filterConfig.getInitParameter("encoding");
        String value = filterConfig.getInitParameter("ignore");
        if(value == null)
            ignore = true;
        else
        if(value.equalsIgnoreCase("true"))
            ignore = true;
        else
        if(value.equalsIgnoreCase("yes"))
            ignore = true;
        else
            ignore = false;
    }

    protected String selectEncoding(ServletRequest request)
    {
        return encoding;
    }

    protected String encoding;
    protected FilterConfig filterConfig;
    protected boolean ignore;
搜索更多相关主题的帖子: 注释 乱码 过滤器 public null 
2008-06-18 17:35
恋轩念伊人
Rank: 5Rank: 5
来 自:湖南衡阳
等 级:贵宾
威 望:19
帖 子:643
专家分:0
注 册:2008-2-23
收藏
得分:0 
不懂

我不是一个随便的人,我随便起来不是人我哦。信不?
2008-06-20 16:04
高寒
Rank: 2
等 级:论坛游民
帖 子:134
专家分:20
注 册:2005-10-25
收藏
得分:0 
这是过滤器代码,主要设置编码格式,主要是在doFilter方法中写过滤代码,过滤之后利用chain.doFilter(request, response);沿过滤链继续向下传递

2008-06-21 09:13
快速回复:中问乱码问题(谁能注释一下这段代码)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012370 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved