📄 characterencodingfilter.java
字号:
package com.fendou.platform;
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;
public class CharacterEncodingFilter implements Filter{
protected FilterConfig config;
protected String encoding=null;
protected boolean enable=true;
public void destroy() {
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
if(this.enable || request.getCharacterEncoding()==null){
String encoding=this.encoding;
if(encoding!=null){
request.setCharacterEncoding(encoding);
response.setCharacterEncoding(encoding);
}
}
response.setContentType("text/html; charset="+encoding);
chain.doFilter(request, response);
}
public void init(FilterConfig config) throws ServletException {
this.config=config;;
this.encoding=config.getInitParameter("encoding");
String value=config.getInitParameter("enable");
if(value==null)
this.enable=false;
else if(value.equalsIgnoreCase("true"))
this.enable=true;
else if(value.equalsIgnoreCase("yes"))
this.enable=true;
else
this.enable=false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -