zoukankan      html  css  js  c++  java
  • Java工具类-设置字符编码

    package common;
    
    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;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    /**
     *    设置字符编码的类,目的是将页面上传过来的数据统一编码为UTF-8,这样做是为了避免当数据插入数据库后会中文乱码问题 
    */
    public class EncodeFilter implements Filter
    {
    
        public void destroy()
        {
            // TODO Auto-generated method stub
    
        }
    
        public void doFilter(ServletRequest arg0, ServletResponse arg1,
                FilterChain chain) throws IOException, ServletException
        {
            HttpServletRequest request = (HttpServletRequest) arg0;
            HttpServletResponse response = (HttpServletResponse) arg1;
            
            request.setCharacterEncoding("utf-8");
            
            chain.doFilter(request, response);
        }
    
        public void init(FilterConfig arg0) throws ServletException
        {
            
        }
    
    }
  • 相关阅读:
    《深度探索C++对象模型》1
    《C++标准库》
    关于多级分类的封装
    git常用命令
    使用BigDecimal进行精确运算
    关于强制装换
    page分页
    pageContext.request.contextPath 和 request.getContextPath()
    springMVC + mybatis 搜索 分页等
    mybatis 动态sql
  • 原文地址:https://www.cnblogs.com/Roni-i/p/9918068.html
Copyright © 2011-2022 走看看