EncodingFilter.java
资源名称:(J2EE)oa.rar [点击查看]
上传用户:lm2018
上传日期:2015-12-12
资源大小:30449k
文件大小:1k
源码类别:
Jsp/Servlet
开发平台:
Java
- package com.oa.module.pub.ectomere;
- 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 EncodingFilter implements Filter {
- String code ="GBK";
- public void init(FilterConfig config) throws ServletException {
- if(config.getInitParameter("code")!=null&&!config.getInitParameter("code").equals("")){
- code = config.getInitParameter("code");
- }
- }
- public void doFilter(ServletRequest req, ServletResponse res,
- FilterChain chain) throws IOException, ServletException {
- req.setCharacterEncoding(code);
- res.setCharacterEncoding(code);
- chain.doFilter(req,res);
- }
- public void destroy() {
- }
- }