gpt4 book ai didi

java - 如何更改HttpServletRequest的 "pathInfo"

转载 作者:行者123 更新时间:2023-11-30 06:36:16 25 4
gpt4 key购买 nike

我不敢问一个奇怪的问题,但我想在 Controller 的处理程序方法中更改 HttpServletRequest 的“pathInfo”。请看下面。

我知道我可以使用 getPathInfo() 获取“pathInfo”。然而。我不知道如何设置 pathInfo。是否可以 ?任何帮助将不胜感激

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

最佳答案

您不能设置这些值。

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

return show2(model, new HttpServletRequestWrapper(request) {
public StringBuffer getRequestURL() {
return new StringBuffer(
super.getRequestURL().toString().replaceFirst("/show1$", "/show2"));
}
});

关于java - 如何更改HttpServletRequest的 "pathInfo",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5092054/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com