Spring application root variable

Now I am accessing my Spring application as follows:

http://localhost:8080/my-app

In my JSPs, I would like to access the root of my application instead of the hardcoding hyperlinks to the main page like <a href="/my-app">. Is there some kind of variable that I can get in my jsps to point to the root of the application? Thanks

+5
source share
2 answers

You can use ${pageContext.request.contextPath}. For example, to get href = "/my-app/somePage", use:

<a href="${pageContext.request.contextPath}/somePage">

URL, cookie. , - JSTL <c:url/>:

<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
...
<a href="<c:url value = '/somePage' />">
+11

getContextPath() .

0

All Articles