📄 charactorencodingfilter.java
字号:
package com.ntsky.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;
/**
* <p>
*
* Title: </p> CharactorEncodingFilter<p>
*
* Description: </p> CharactorEncodingFilter <p>
*
* Copyright: Copyright (c) 2005</p> <p>
*
* Company: </p>
*
*@author not attributable
*@version 1.0
*/
public class CharactorEncodingFilter implements Filter {
private FilterConfig filterConfig;
/**
* Description of the Method
*
*@param filterConfig Description of Parameter
*@exception ServletException Description of Exception
*@since empty
*/
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
}
/**
* Description of the Method
*
*@param request Description of Parameter
*@param response Description of Parameter
*@param chain Description of Parameter
*@exception IOException Description of Exception
*@exception ServletException Description of Exception
*@since empty
*/
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest)request;
String convert = GenericUtil.trim(filterConfig.getInitParameter("NEED_CONVERT"));
String encoding = GenericUtil.trim(filterConfig.getInitParameter("ENCODING"));
if(Boolean.valueOf(convert).booleanValue() && !GenericUtil.isNullOrBlank(encoding)) {
if(!GenericUtil.trim(req.getCharacterEncoding()).equalsIgnoreCase(encoding)) {
req.setCharacterEncoding(encoding);
}
}
try {
chain.doFilter(request, response);
}
catch(Exception ex) {
ex.printStackTrace();
}
}
/**
* Description of the Method
*
*@since empty
*/
public void destroy() {
this.filterConfig = null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -