@RequestMapping(value = {"/search"}) public String errorPath(HttpServletResponse response, @RequestParam(value = "keyword") String keyword, @RequestParam(value = "via") String via) throws IOException { response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY); String url = "/search/"+ URLEncoder.encode(keyword, "UTF-8")+"/4"; response.setHeader("Location", url); response.sendRedirect(url); return ""; }
在这个例子中,如果没有加URLEncoder.encode(keyword, "UTF-8"),运行的时候会发现生成的url是有问题的,
这个时候就需要把keyword给encoder.