tomcat部署war包,页面传递中文参数报错。
传递中文参数需要编码和解码
前端传递参数编码
var targetUrl = "${basePath}/search?keyword=" + encodeURIComponent(encodeURIComponent(strSearch));
window.location.href= targetUrl;
后端接收参数解码
@RequestMapping("search")
public String search(Model model,String keyword) throws UnsupportedEncodingException {
keyword = URLDecoder.decode(keyword, "utf-8");
model.addAttribute("keyword",keyword);
return "web/search";
}