0

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

1

1 Answer 1

0

There is no such function in Java.

You have to roll your own, with all the gotchas and edge cases.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.