我想將 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);}我用來獲取的示例 url - http://localhost:8080/app/controller/redirectionTest/1234/http://localhost:3000/main因此,當我調用 GET 方法時,我想運行一些代碼,然后將其重定向到http://localhost:3000/main但 URL 中有斜杠,因此無法運行。
2 回答

長風秋雁
TA貢獻1757條經驗 獲得超7個贊
用標準代碼替換斜杠:%2F
.
http://localhost:8080/app/controller/redirectionTest/1234/http%3A%2F%2Flocalhost%3A3000%2Fmain
我已將冒號替換為%3A
以防萬一您對此也有疑問

蕭十郎
TA貢獻1815條經驗 獲得超13個贊
你可以試試這個
@RequestMapping(value = { "/mapping/{param1}" }, method = { RequestMethod.GET})
public void mapping(HttpServletResponse response, @PathVariable("param1") String param1, @RequestParam(required = true, value = "redirectLink") String redirectLink) throws IOException {
// code i wanna run
response.sendRedirect(redirectLink);
}
現在,訪問http://localhost:8080/app/controller/redirectionTest/1234?redirectLink=http://localhost:3000/main
添加回答
舉報
0/150
提交
取消