js页面之间以及vue $http请求向后台传递参数中文乱码问题解决

来源:互联网 发布:linux重启后时间不对 编辑:程序博客网 时间:2024/05/21 12:42

页面传参:
本页面的js先对参数进行编码
window.location="detail.html?"+encodeURI(encodeURI("country=中国"));

在detail页面获取参数时:

decodeURI(window.location.href)

这样得到的地址,里面的中文不会乱码


$http异步请求向后台传参数:

同样对参数进行编码encodeURI(encodeURI("country=中国"));

java后台获取参数的时候使用

 public @ResponseBody String getData(String country){        try {            country= URLDecoder.decode(country,"utf-8");        } catch (UnsupportedEncodingException e) {            e.printStackTrace();        }System.out.print(country);        return "index";}

获取参数


 
原创粉丝点击