用EL获取绝对URL [英] get absolute URL with EL

查看:139
本文介绍了用EL获取绝对URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用当前协议,端口,应用程序等在当前服务器上不使用scriptlet(仅EL)构建绝对URL?

How can I build up an absolute URL using no scriptlets (only EL) to the current server, using the current protocol, port, application etc?

推荐答案

您可以在 JSTL 的帮助下,使用上下文根获取基本URL,如下所示:

You can get the base URL up to with the context root with help of JSTL as follows:

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
...
<c:set var="baseURL" value="${fn:replace(pageContext.request.requestURL, pageContext.request.requestURI, pageContext.request.contextPath)}" />
...
<link rel="stylesheet" href="${baseURL}/foo.css" />
<script src="${baseURL}/foo.js"></script>
<a href="${baseURL}/foo.jsp">link</a>

这篇关于用EL获取绝对URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆