浏览器地址栏中参数有中文会报400错误,导致无法进入后台

解决方法:

  1.js编码encodeURI(encodeURI(URL)),编码两次
  
  2.服务器端解码 URLDecoder.decode(request.getParameter("para"),"UTF-8")
controller层:
@RequestMapping("/index")
public ModelAndView index(HttpServletRequest request,HttpServletResponse response) {
  String name = request.getParameter("name");
  if (null != name){
    try {
        name = URLDecoder.decode(request.getParameter("name"),"UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
  }
}

name传参在地址栏显示的是加密过的:%25E6%2596%25B0%25E7%2596%2586%25E5%2585%25AC%25E5%258F%25B8 如这段,经过URLDecoder.decode解密,可得中文参数

转载自:https://blog.csdn.net/tornado430/article/details/82706374

你可能感兴趣的:(java)