首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何更改HttpServletRequest的"pathInfo“

如何更改HttpServletRequest的"pathInfo“
EN

Stack Overflow用户
提问于 2011-02-23 22:14:53
回答 2查看 3.2K关注 0票数 2

我不敢问一个奇怪的问题,但我想在控制器的处理程序方法中更改HttpServletRequest的"pathInfo“。请看下面的内容。

我知道我可以通过使用getPathInfo()获得"pathInfo“。然而。我不知道如何设置pathInfo。有可能吗?任何帮助我们都将不胜感激。

代码语言:javascript
复制
@RequestMapping(value = "show1" method = RequestMethod.GET)
public String show1(Model model, HttpServletRequest request) {

    // I want to set up "PathInfo" but this kind of methods are not provided 
    //request.setPathInfo("/show2");

    // I thought that BeanUtils.copy may be available.. but no ideas.

    // I have to call show2() with the same request object
    return show2(model, request);
}

// I am not allowed to edit this method
private String show2(Model model, HttpServletRequest request) {

    // I hope to display "http://localhost:8080/contextroot/show2"
    System.out.println(request.getRequestURL());

    return "complete";
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-02-23 22:23:39

您不能设置这些值。

唯一的选择是为您的请求创建一个包装器,如下所示:

代码语言:javascript
复制
return show2(model, new HttpServletRequestWrapper(request) {
    public StringBuffer getRequestURL() {
        return new StringBuffer(
            super.getRequestURL().toString().replaceFirst("/show1$", "/show2"));
    }
});
票数 4
EN

Stack Overflow用户

发布于 2011-02-23 22:21:03

Path Info由浏览器(客户端)在请求某个URL时设置。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5092054

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档