characterencodingfilter.java
来自「网上商城代码」· Java 代码 · 共 53 行
JAVA
53 行
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 + =
减小字号Ctrl + -
显示快捷键?