Relative URIs in JSP/Servlet Web Application
843838Nov 16 2005 — edited Nov 16 2005Hi all,
I have a web application running on Tomcat with the following directory structure...
All jsp files in...
Tomcat\webapps\myweb\*.jsp
All servlet class files in...
Tomcat\webapps\myweb\servlet\WEB-INF\classes\
I use the following code construct a lot in my servlets...
myRelativeURL = TWJspConstants.LOGIN_JSP_PAGE;
getServletConfig().getServletContext().getRequestDispatcher(myRelativeURL).forward(request, response);
In the above case, TWJspConstants.LOGIN_JSP_PAGE = "/login.jsp";
Now, I have a jsp page "Tomcat\webapps\myweb\login_failure.jsp", which needs to contain a hyper-link to TWJspConstants.LOGIN_JSP_PAGE.
But when I use it, the hyperlink becomes "http://localhost/login.jsp" rather than "http://localhost/myweb/login.jsp".
I can hardcode the hyperlink, but I dont want to do that.
Can anyone please explain how to deal with relative URIs when it comes to servlets and jsps.
Thanks,
Joe.