<c:url var="myUrl" value="/MyPath/${MyID}"/>
which I then use later (to enable users to copy links) :
<input size="35" disabled value="${myUrl}" />
and it shows
/my-app-name/MyPath/23
however I want it to be
http://myHost/my-app-name/MyPath/23
I can prepend the string sure, but wanted a way to actively get the correct hostname ... ?
You need to prepare it yourself based on HttpServletRequest#getRequestURL()
and a little help of JSTL functions:
<c:set var="req" value="${pageContext.request}" />
<c:set var="baseURL" value="${fn:replace(req.requestURL, fn:substring(req.requestURI, 1, fn:length(req.requestURI)), req.contextPath)}" />
...
<c:url var="myUrl" value="${baseURL}/${MyID}"/>
HttpServletRequest object has all the details:
getProtocol
getServerName
getContextPath
so I think you can use:
${request.protocol} :// ${request.serverName} ${request.contextPath} /etc
to build what you want.
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