Short Version
How to convert:
/Something.jsp
into
/WEB-ROOT/Something.jsp?
What is the Java equivalent of the .NET:
resolveUrl("~/images/DownArrow.png");
//...or...
System.Web.VirtualPathUtility.ToAbsolute("~/images/DownArrow.png");
Which returns something like:
/WEB-ROOT/Images/DownArrow.png
Long Version
The terminology we're going to use:
Path | Example |
---|---|
Application relative path | /images/DownArrow.png |
Application absolute path | /WEB-ROOT/images/DownArrow.png |
Virtual path | https://contoso.org/WEB-ROOT/images/DownArrow.png |
Given a relative path, i need the absolute path.
Is issue, of course, is that there are parts of the URL i don't know or control:
https://contoso.org /WEB-ROOT /images/DownArrow.png
https://contoso.org /Helpdesk /images/DownArrow.png
https://contoso.org /images/DownArrow.png
https://192.168.10.17 /images/DownArrow.png
https://192.168.10.17 /Helpesk /images/DownArrow.png
https://192.168.10.17 /WEB-ROOT /images/DownArrow.png
\___________________/ \_______/ \___________________/
host appname absolutepath
(optional)
All i know is /images/DownArrow.png
and i need it resolved into {appname}/images/DownArrow.png
The Issue
I want to add a link to a .jsp
page, e.g.:
<A href="/AccountStatus.jsp">Account status</A>
Except that /AccountStatus.jsp
doesn't work, because the .jsp
page is not in the "root" of the web-site.
Technically the .jsp
files lives in a sub-folder off the "root" on my hard drive called WebRoot
:
- WebRoot
- AccountStatus.jsp
So if i try to update the link:
<A href="/WebRoot/AccountStatus.jsp">Account status</A>
That doesn't work either, because there's actually another different secret folder that HTML content is located in, and it is only knowable at runtime on the hosted application server:
<A href="/WEB-ROOT/AccountStatus.jsp">Account status</A>
Except that name can be modified to something else (i don't know how - but it can):
<A href="/GptThree/AccountStatus.jsp">Account status</A>
How to resolve path to jsp page?
So we now have the question: how to resolve the URL of page so i can give it as a URL to the client.
It .NET it is:
<A href="<%= ResolveUrl("~/AccountStatus.jsp")%>">Account status</A>
Which in Java could be something like:
<A href="<%= resolveUrl("~/AccountStatus.jsp")%>">Account status</A>
Except i need to know where resolveUrl
method lives.
Research Effort
- How to get back to root link in jsp
- How could i change the url when forwarding to a page
- Cannot resolve controller URL from JSP
- Absolute url in jsp
- How to resolve URL issue while hosting?: "You should not be hard-coding the domain into your URLs. You should be using server-relative URLs or context-relative URLs (depending upon whether the reference is from the client or server, respectively). That way, the application works no matter where it is deployed."
- What is the difference between ResolveUrl and ResolveClientUrl?
- ASP.NET relative path
- How to use relative paths without including the context root name?
- How to calculate the relative path of JSP
- I wrote a relative path in JSP but it's not working
- Retrieving relative url path of file inside a include file, jsp
- relative and absolute path