which I then use later (so that users can copy links)...">

Access full url including hostname using jstl

<c:url var="myUrl" value="/MyPath/${MyID}"/> 

which I then use later (so that users can copy links):

 <input size="35" disabled value="${myUrl}" /> 

and he shows

 /my-app-name/MyPath/23 

however I want him to be

 http://myHost/my-app-name/MyPath/23 

I can add the string confidently, but would like to actively get the correct hostname ...?

+7
source share
2 answers

You need to prepare it yourself based on HttpServletRequest#getRequestURL() and help a little 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}"/> 
+22
source

The HttpServletRequest object has all the details:

  • getProtocol
  • getServerName
  • getContextPath

so i think you can use:

 ${request.protocol} :// ${request.serverName} ${request.contextPath} /etc 

to create what you want.

+7
source

All Articles