乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      【重點(diǎn)】亂碼問(wèn)題 java web 動(dòng)態(tài)代理

       一本正經(jīng)地胡鬧 2020-04-28

      程序設(shè)計(jì):添加一個(gè)專門測(cè)試亂碼的前端和后端。

      這樣可以分析測(cè)試各種亂碼情況:form表單提交,ajax提交。以此來(lái)推測(cè)出哪里出問(wèn)題,程序大致是如何設(shè)置的。

      ajax的post提交,后臺(tái)不用處理,中文也不會(huì)亂碼。(因?yàn)閖query處理了)

      ajax的get提交,后臺(tái)需要處理,要么getBytes(),new String();要么改tomcat配置。

      filter中使用動(dòng)態(tài)代理對(duì)全局進(jìn)行編碼:

      public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)

      throws IOException, ServletException {

      final HttpServletRequest req = (HttpServletRequest) request;

      //使用動(dòng)態(tài)代理完成全局編碼

      HttpServletRequest enhanceRequset = (HttpServletRequest) Proxy.newProxyInstance(

      req.getClass().getClassLoader(), 

      req.getClass().getInterfaces(), 

      new InvocationHandler() {

      @Override

      public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

      //對(duì)getParameter方法進(jìn)行增強(qiáng)

      String name = method.getName();//獲得目標(biāo)對(duì)象的方法名稱

      if("getParameter".equals(name)){

      String invoke = (String) method.invoke(req, args);//亂碼

      //轉(zhuǎn)碼

      invoke = new String(invoke.getBytes("iso8859-1"),"UTF-8");

      return invoke;

      }

      return method.invoke(req, args);

      }

      }

      );

      chain.doFilter(enhanceRequset, response);

      }

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多