Link path for redirect

后端 未结 1 1421
说谎
说谎 2021-01-24 22:02

I\'m trying to redirect my response but I got stuck at the link path.

The following command takes me to the tomcat\'s localhost and searches for the page there but it ca

相关标签:
1条回答
  • 2021-01-24 22:39

    A relative redirect URL is relative to the current request URL (the one as you see in the browser address bar). The leading / will take you to the domain root. The behaviour is perfectly predictable and normal. If the myPage.html is in the same folder as the current request URL, then you can just remove the leading /:

    response.sendRedirect("myPage.html");
    

    Or if that is never reliably predictable because the current request URL can come from anywhere in your webapp, then just dynamically include the context path:

    response.sendRedirect(request.getContextPath() + "/myPage.html");
    
    0 讨论(0)
提交回复
热议问题