资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

REq,RES编码设置-创新互联


import java.io.IOException;REq,RES编码设置

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;
import javax.servlet.http.HttpServletResponse;

创新互联建站专注于企业成都营销网站建设、网站重做改版、襄城网站定制设计、自适应品牌网站建设、HTML5商城系统网站开发、集团公司官网建设、成都外贸网站制作、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为襄城等各大城市提供网站开发制作服务。

public class SetCharacterEncodingFilter implements Filter {

private FilterConfig filterConfig;

public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
}

public void doFilter(ServletRequest req, ServletResponse res,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest request;
HttpServletResponse response;
try {
request = (HttpServletRequest) req;
response = (HttpServletResponse) res;
} catch (ClassCastException e) {
throw new ServletException("non-HTTP request or response");
}

String encoding = filterConfig.getInitParameter("encoding");
if(encoding==null){
encoding = "UTF-8";
}

//POST:
request.setCharacterEncoding(encoding);
response.setCharacterEncoding(encoding);
response.setContentType("text/html;charset="+encoding);
chain.doFilter(request, response);
}

public void destroy() {

}

}

做做笔记,传播知识,我是个勤劳的搬运工 1224144402@qq.com
分享题目:REq,RES编码设置-创新互联
文章转载:http://cdkjz.cn/article/cccsgp.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220