Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use <code>HttpServletRequest#getRequestURI()</code> to obtain the request URI. The <code>getServletPath()</code> as suggested by the other answer is not necessarily helpful as it represents the servlet path (the matching part in the JSP/Servlet URL pattern), not the request URI (as the enduser sees in the browser address bar). If the JSP was been forwarded by some front controller servlet, you would get the JSP's own path instead of the virtual path as in the browser address bar.</p> <p>Assuming that you have a menu which is represented by a <code>List&lt;Page&gt;</code> in the application scope where the <code>Page</code> class has <code>url</code> and <code>name</code> properties, here's a kickoff example with help of <a href="https://stackoverflow.com/tags/jstl/info">JSTL</a>:</p> <pre class="lang-xml prettyprint-override"><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;ul id="menu"&gt; &lt;c:forEach items="${menu}" var="page"&gt; &lt;c:set var="active" value="${fn:endsWith(pageContext.request.requestURI, page.url)}" /&gt; &lt;li class="${active ? 'active' : 'none'}"&gt;&lt;a href="${page.url}"&gt;${page.name}&lt;/a&gt;&lt;/li&gt; &lt;/c:forEach&gt; &lt;/ul&gt; </code></pre> <p>You can then define the menu item style by the <code>.active</code> class. E.g. giving it a black color, some highlighting background, etc.</p> <pre><code>ul#menu li { background: white; } ul#menu li.active { background: pink; } </code></pre>
    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. 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.
    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