我想将 URL 放入 GET 请求中,这样我就可以将用户重定向到给定的 URL。
这是我到目前为止的代码:
@RequestMapping(value = { "/mapping/{param1}/{redirectLink}" }, method = { RequestMethod.GET})
public void mapping(HttpServletResponse response, @PathVariable("param1") String param1, @PathVariable("redirectLink") String redirectLink) throws IOException {
// code i wanna run
response.sendRedirect(backLink);
}
我用来获取的示例网址 - http://localhost:8080/app/controller/redirectionTest/1234/http://localhost:3000/main
因此,当我调用 GET 方法时,我想运行一些代码,然后重定向到 http://localhost:3000/main但 URL 中有斜线,所以不可能。
最佳答案
用标准代码替换斜杠:%2F
。
http://localhost:8080/app/controller/redirectionTest/1234/http%3A%2F%2Flocalhost%3A3000%2Fmain
我已将冒号替换为 %3A
以防万一您也遇到问题
关于java - 如何将 url 作为 @PathVariable 传递给 spring RestController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54634488/