Send redirect to relative path in JSP?

2020-01-29 08:23发布

response.sendRedirect("../seja/izpisknjig.jsp");

the file in which I execute this line is index.jsp. the directory structure looks like this.
project
--index.jsp
seja
--izpisknjig.jsp

How do I form the relative path to redirect to izpisknjig.jsp.

3条回答
欢心
2楼-- · 2020-01-29 08:36

You may be overthinking this. You could just pier some generate some javascript to redirect anywhere you like.

  document.location = "MyPage.php?action=DoThis";
查看更多
Viruses.
3楼-- · 2020-01-29 08:38

You can use JSP taglib to do redirection.

Content of index.jsp file :

<jsp:forward page="../seja/izpisknjig.jsp" />

If project and seja are at root of your webapp context ( ie. http://host:port/context/project )

Content of index.jsp file :

<jsp:forward page="/seja/izpisknjig.jsp" />
查看更多
混吃等死
4楼-- · 2020-01-29 08:39

Most reliable would be to create a domain-relative URL with the context path included.

response.sendRedirect(request.getContextPath() + "/seja/izpisknjig.jsp");
查看更多
登录 后发表回答