熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java核心技術 >> 正文

非常優秀的AJAX中文問題解決過濾器

2022-06-13   來源: Java核心技術 
    public class AjaxEncodeFilter extends HttpServlet implements Filter {
   
    /**
   
    * AJAX使用中的字符過濾器解決中文問題
   
    */
   
    private static final long serialVersionUID = L;
   
    public void doFilter(ServletRequest servletRequest
   
    ServletResponse servletResponse FilterChain filterChain)
   
    throws IOException ServletException {
   
    /*  if (loggerisDebugEnabled()) {
   
    loggerdebug(doFilter(ServletRequest ServletResponse FilterChain) start //$NONNLS$
   
    }  */
   
    HttpServletRequest request = (HttpServletRequest) servletRequest;
   
    HttpServletResponse response = (HttpServletResponse) servletResponse;
   
    String requestedWith = requestgetHeader(xrequestedwith
   
    String type = requestgetContentType()
   
    if (requestedWith != null && XMLHttpRequestequals(requestedWith)
   
    && null != type
   
    && application/xwwwformurlencodedequals(type)) {
   
    // (Thiss ajax postset encode is UTF
   
    requestsetCharacterEncoding(UTF
   
    responsesetCharacterEncoding(UTF
   
    requestgetParameterMap()
   
    }
   
    filterChaindoFilter(request response)
   
    /*  if (loggerisDebugEnabled()) {
   
    loggerdebug(doFilter(ServletRequest ServletResponse FilterChain) end //$NONNLS$
   
    }  */
   
    }
   
    public void init(FilterConfig arg) throws ServletException {
   
    // TODO Autogenerated method stub
   
    }
   
    }


From:http://tw.wingwit.com/Article/program/Java/hx/201311/26232.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.