If a have <c:url value="/article"/>
in a jsp, I actually want it to produce http://mysite.com/context/article
. Is there any simple way to acheive this?
Linking with absolute URLs The domain is the name of the website. For example, the domain name of Indiana University's central web server is www.indiana.edu . The path includes directory and file information. You must use absolute URLs when referring to links on different servers.
What is an absolute URL? An absolute URL is the full URL, including protocol ( http / https ), the optional subdomain (e.g. www ), domain ( example.com ), and path (which includes the directory and slug). Absolute URLs provide all the available information to find the location of a page.
An absolute URL contains all the information necessary to locate a resource. In context to the Cart.com online stores system it begins with https://. For example, https://cart.com is an absolute URL.
An absolute URL contains the entire address from the protocol (HTTPS) to the domain name (www.example.com) and includes the location within your website in your folder system (/foldernameA or /foldernameB) names within the URL. Basically, it's the full URL of the page that you link to.
There's no simple way. Either hardcode it or output the following:
${fn:replace(pageContext.request.requestURL, pageContext.request.requestURI, '')}${pageContext.request.contextPath}
Cumbersome, but there's no shorter/nicer way when you want to take the protocol and port parts of the URL correctly into account. You can at highest assign ${pageContext.request}
to ${r}
.
<c:set var="r" value="${pageContext.request}" />
so that you can end up with this
${fn:replace(r.requestURL, r.requestURI, '')}${r.contextPath}
That said, I only fail to see how this requirement is useful/valuable. I always code my webapp-specific links to be relative to the current context or to the HTML <base>
tag. Otherwise you'll have to a lot of maintenance when your domain, port and/or even the context changes. Why this requirement?
<base>
tag? (sensitive subject actually)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With