java 旧url 处理的解决方法

   @RequestMapping(value = {"/search"})
    public void errorPath(HttpServletResponse response,
                            @RequestParam(value = "keyword") String keyword,
                            @RequestParam(value = "via") String via) throws IOException {
        response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);  //对于旧的url,/search?keyword=***&via=***使它们永久性的跳转到新的url
        String url = "/search/"+ URLEncoder.encode(keyword, "UTF-8")+"/4";
        response.setHeader("Location", url); //请求的资源已经移动到新的地址
        response.flushBuffer();
    }

对于旧的url,/search?keyword=***&via=***使它们永久性的跳转到新的url    /search/keyword/4

posted @ 2016-12-27 14:59  侧耳倾听的世界  阅读(178)  评论(0编辑  收藏  举报