EncodingFilter.java
上传用户:nbxinmin
上传日期:2021-10-09
资源大小:46k
文件大小:1k
源码类别:

Internet/IE编程

开发平台:

Java

  1. package com.xdf.exams.filter;
  2. import java.io.IOException;
  3. import javax.servlet.Filter;
  4. import javax.servlet.FilterChain;
  5. import javax.servlet.FilterConfig;
  6. import javax.servlet.ServletException;
  7. import javax.servlet.ServletRequest;
  8. import javax.servlet.ServletResponse;
  9. import javax.servlet.http.HttpServletRequest;
  10. public class EncodingFilter implements Filter{
  11. public void destroy() {
  12. }
  13. public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
  14. HttpServletRequest request = (HttpServletRequest)req;
  15. //设置请求中文
  16. request.setCharacterEncoding("GBK");
  17. //继续处理
  18. chain.doFilter(req,resp);
  19. }
  20. public void init(FilterConfig config) throws ServletException {
  21. }
  22. }