Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The web application name (actually the context path) is available by calling <a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpServletRequest.html#getContextPath%28%29" rel="noreferrer"><code>HttpServletrequest#getContextPath()</code></a> (and thus NOT <code>getServletPath()</code> as one suggested before). You can retrieve this in JSP by <code>${pageContext.request.contextPath}</code>. </p> <pre><code>&lt;p&gt;The context path is: ${pageContext.request.contextPath}.&lt;/p&gt; </code></pre> <p>If you intend to use this for all relative paths in your JSP page (which would make this question more sense), then you can make use of the HTML <code>&lt;base&gt;</code> tag:</p> <pre><code>&lt;%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %&gt; &lt;%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %&gt; &lt;c:set var="req" value="${pageContext.request}" /&gt; &lt;c:set var="url"&gt;${req.requestURL}&lt;/c:set&gt; &lt;c:set var="uri" value="${req.requestURI}" /&gt; &lt;!doctype html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;title&gt;SO question 2204870&lt;/title&gt; &lt;base href="${fn:substring(url, 0, fn:length(url) - fn:length(uri))}${req.contextPath}/"&gt; &lt;script src="js/global.js"&gt;&lt;/script&gt; &lt;link rel="stylesheet" href="css/global.css"&gt; &lt;/head&gt; &lt;body&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="home.jsp"&gt;Home&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="faq.jsp"&gt;FAQ&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="contact.jsp"&gt;Contact&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>All links in the page will then automagically be relative to the <code>&lt;base&gt;</code> so that you don't need to copypaste the context path everywhere. Note that when relative links start with a <code>/</code>, then they will not be relative to the <code>&lt;base&gt;</code> anymore, but to the domain root instead.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload