📄 encodingfilter.java
字号:
/*
*
* Title: The ERP System of kelamayi Downhole Company [PMIP]
*
* Copyright: Copyright (c) 2004
*
* Company: westerasoft Co., Ltd
*
* All right reserved.
*
* Created on 2004-4-8
*
* JDK version used :1.4.1
*
* Modification history:
*
*/
package com.hope.common.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;
/**
* 设置字符集过滤
* @version Version 1.0 <br/>
* @author 刘宏德
*/
public class EncodingFilter
implements Filter {
/**
* 字符编码集
*/
protected String encoding = null;
/**
* 过滤器配置对象
*/
protected FilterConfig filterConfig = null;
/**
* 取消过滤标志
*/
protected boolean ignore = true;
/**
* 注销filter服务
*/
public void destroy() {
this.encoding = null;
this.filterConfig = null;
}
/**
* 获取设定的字符集,对request中的参数进行字符集设定
*
* @param request The servlet request we are processing
* @param result The servlet response we are creating
* @param chain The filter chain we are processing
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet error occurs
*/
public void doFilter(
ServletRequest request,
ServletResponse response,
FilterChain chain) throws IOException, ServletException {
if (ignore || (request.getCharacterEncoding() == null)) {
request.setCharacterEncoding(selectEncoding(request));
}
chain.doFilter(request, response);
}
/**
* 初始化Filter参数
* @param filterConfig The filter configuration object
*/
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") || value.equalsIgnoreCase("yes"))
this.ignore = true;
else
this.ignore = false;
}
/**
* 获取用户设定的字符集,如没有设定,返回null。
*
* @param request The servlet request we are processing
*/
protected String selectEncoding(ServletRequest request) {
return (this.encoding);
}
/**
* 返回FilterConfig对象。
* @return FilterConfig
*/
public FilterConfig getFilterConfig() {
return filterConfig;
}
/**
* 设置FilterConfig对象。
* @param filterConfig The filterConfig to set
*/
public void setFilterConfig(FilterConfig filterConfig) {
this.filterConfig = filterConfig;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -