页面传参:
本页面的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";
}
获取参数