访问完整的URL,包括使用jstl的主机名 [英] Accessing the full url, including hostname with jstl
本文介绍了访问完整的URL,包括使用jstl的主机名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<c:url var="myUrl" value="/MyPath/${MyID}"/>
我稍后会使用它(以使用户能够复制链接):
which I then use later (to enable users to copy links) :
<input size="35" disabled value="${myUrl}" />
它显示
/my-app-name/MyPath/23
但我想要它是
http://myHost/my-app-name/MyPath/23
我可以预先确定字符串,但想要一种主动获取正确主机名的方法......?
I can prepend the string sure, but wanted a way to actively get the correct hostname ... ?
推荐答案
您需要根据 HttpServletRequest#getRequestURL()
以及 JSTL函数:
<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}"/>
这篇关于访问完整的URL,包括使用jstl的主机名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文