Absolute url in jsp

2019-01-26 14:29发布

While including css, js and images in my jsps I am facing a problem resolving relative urls. The urls get changed on refreshing the page or clicking the back button. I suppose one solution to the problem would be to include external files by using absolute urls. But I can't find out how to use a reference to the relative url and use it. Can anyone please help me on this?

标签: jsp url jsf
2条回答
叛逆
2楼-- · 2019-01-26 15:08

This would also work and may be easier to read and has some extra benefits such as proper escaping and optional inclusion of parameters

<link href="<c:url value="/style/style.css"/>" rel="stylesheet" type="text/css" />

查看更多
贪生不怕死
3楼-- · 2019-01-26 15:11

Is this what you're looking for?

${pageContext.servletContext.contextPath}

and then in your jsp:

<link rel="stylesheet" href="${pageContext.servletContext.contextPath}/css/page.css"   media="all"    type="text/css" />
查看更多
登录 后发表回答