在请求目标中找到无效字符。有效字符在RFC 7230和RFC 3986中定义

944 阅读1分钟

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";
}