zoukankan      html  css  js  c++  java
  • springmvc前台传递到controller层的中文乱码解决方法

    
    
    
    
       @RequestMapping("/judge")
        public String judgeLogger(@RequestParam String userName, @RequestParam String password, @RequestParam String sex, RedirectAttributes redirectAttributes) {
    //    乱码解决方法
            try {
                String name = new String(userName.getBytes("iso-8859-1"), "UTF-8");
                String s = new String(sex.getBytes("iso-8859-1"), "utf-8");

    //--------------------------------------------------------------------------------
    if (name != null && password != null && s != null) { if (loggerService.judgeLogger(name)==1) { redirectAttributes.addFlashAttribute("userName",name); redirectAttributes.addFlashAttribute("password",password); redirectAttributes.addFlashAttribute("sex",s); return "redirect:/log.do"; } } } catch (UnsupportedEncodingException e) { e.printStackTrace(); return "404"; } return "404"; }
    
    
    
    在传递过来的前台数据进行一次转码即可解决。但是我之前设置过request和response的编码,但是然并卵。
    
    
    
     
    没有虚过一天,真好
  • 相关阅读:
    十天冲刺之一
    每日日报2021 4/30
    每日日报2021 4/29
    每日日报2021 4/28
    每日日报2021 4/27
    每日日报2021 4/26
    每日日报2021 4/24
    每日日报2021 4/23
    《梦断代码》读后感
    273. Integer to English Words
  • 原文地址:https://www.cnblogs.com/dailinfu/p/6344680.html
Copyright © 2011-2022 走看看