1 Star 0 Fork 0

bqYBQ/SMBMS

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
EnCodingFilter.java 1.26 KB
一键复制 编辑 原始数据 按行查看 历史
bqYBQ 提交于 2018-09-06 15:38 . test
package cn.bdqn.filter;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebFilter(filterName = "EnCodingFilter",urlPatterns ={"/*"} ,initParams={@WebInitParam(name="charset",value ="utf-8"),
@WebInitParam(name="contentType",value ="text/html;charset=utf-8")})
public class EnCodingFilter implements Filter {
private String charset;
private String contentType;
public void destroy() {
}
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
HttpServletRequest request= (HttpServletRequest) req;
HttpServletResponse response= (HttpServletResponse) resp;
request.setCharacterEncoding(charset);
response.setCharacterEncoding(charset);
response.setContentType(contentType);
int i=0;
chain.doFilter(request,response);
}
public void init(FilterConfig config) throws ServletException {
charset = config.getInitParameter("charset");
contentType = config.getInitParameter("contentType");
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/yaobaiquan/SMBMS.git
[email protected]:yaobaiquan/SMBMS.git
yaobaiquan
SMBMS
SMBMS
master

搜索帮助