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的編碼,但是然並卵。

 

 
        

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM