Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think it helps more if you see with your own eyes that it can actually be done entirely <strong>without</strong> scriptlets. </p> <p>Here's a 1 on 1 rewrite with help of among others <a href="http://java.sun.com/products/jsp/jstl/1.1/docs/tlddocs/index.html" rel="noreferrer">JSTL</a> (just drop <a href="http://download.java.net/maven/1/jstl/jars/jstl-1.2.jar" rel="noreferrer"><code>jstl-1.2.jar</code></a> in <code>/WEB-INF/lib</code>) <a href="http://java.sun.com/products/jsp/jstl/1.1/docs/tlddocs/c/tld-summary.html" rel="noreferrer">core</a> and <a href="http://java.sun.com/products/jsp/jstl/1.1/docs/tlddocs/fn/tld-summary.html" rel="noreferrer">functions</a> taglib:</p> <pre class="lang-xml prettyprint-override"><code>&lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %&gt; &lt;%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;My Events - &lt;decorator:title /&gt;&lt;/title&gt; &lt;link href="${pageContext.request.contextPath}/assets/styles.css" rel="stylesheet" type="text/css" /&gt; &lt;/head&gt; &lt;body&gt; &lt;div class="tabs"&gt; &lt;a ${fn:contains(pageContext.request.requestURI, '/events/') ? 'class="selected"' : ''} href="${pageContext.request.contextPath}/events/Listing.action"&gt;Events&lt;/a&gt; &lt;a ${fn:contains(pageContext.request.requestURI, '/people/') ? 'class="selected"' : ''} href="${pageContext.request.contextPath}/people/Listing.action"&gt;People&lt;/a&gt; &lt;/div&gt; &lt;div class="submenu"&gt; &lt;c:if test="${fn:contains(pageContext.request.requestURI, '/events/')}"&gt; &lt;a href="Listing.action"&gt;List of Events&lt;/a&gt; |&lt;a href="New.action"&gt;New Event&lt;/a&gt; &lt;/c:if&gt; &lt;c:if test="${fn:contains(pageContext.request.requestURI, '/people/')}"&gt; &lt;a href="Listing.action"&gt;List of People&lt;/a&gt; |&lt;a href="New.action"&gt;New Person&lt;/a&gt; &lt;/c:if&gt; &amp;nbsp; &lt;/div&gt; </code></pre> <p>Here's a more optimized rewrite, note that I used <code>c:set</code> to "cache" expression results for reuse and that I use HTML <code>&lt;base&gt;</code> tag to avoid putting the context path in every link (just make all relative URL's in your webpage relative to it --without the leading slash!):</p> <pre class="lang-xml prettyprint-override"><code>&lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %&gt; &lt;%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %&gt; &lt;c:set var="isEvents" value="${fn:contains(pageContext.request.requestURI, '/events/')}" /&gt; &lt;c:set var="isPeople" value="${fn:contains(pageContext.request.requestURI, '/people/')}" /&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;My Events - &lt;decorator:title /&gt;&lt;/title&gt; &lt;base href="${pageContext.request.contextPath}"&gt; &lt;link href="assets/styles.css" rel="stylesheet" type="text/css" /&gt; &lt;/head&gt; &lt;body&gt; &lt;div class="tabs"&gt; &lt;a ${isEvents ? 'class="selected"' : ''} href="events/Listing.action"&gt;Events&lt;/a&gt; &lt;a ${isPeople ? 'class="selected"' : ''} href="people/Listing.action"&gt;People&lt;/a&gt; &lt;/div&gt; &lt;div class="submenu"&gt; &lt;c:if test="${isEvents}"&gt; &lt;a href="Listing.action"&gt;List of Events&lt;/a&gt;|&lt;a href="New.action"&gt;New Event&lt;/a&gt; &lt;/c:if&gt; &lt;c:if test="${isPeople}"&gt; &lt;a href="Listing.action"&gt;List of People&lt;/a&gt;|&lt;a href="New.action"&gt;New Person&lt;/a&gt; &lt;/c:if&gt; &amp;nbsp; &lt;/div&gt; </code></pre> <p>It can actually be optimized more if you collect all those "hardcoded" values like <code>events</code> and <code>people</code> and link texts in a <code>Map</code> in the application scope and use under each the JSTL <code>&lt;c:forEach&gt;</code> to display the tabs.</p> <p>As to your <strong>actual</strong> question, you can <em>disable</em> scriptlets (and get runtime errors about using it) by adding the following entry in webapp's <code>web.xml</code>. It may help to spot overseen scriptlets.</p> <pre class="lang-xml prettyprint-override"><code>&lt;jsp-config&gt; &lt;jsp-property-group&gt; &lt;url-pattern&gt;*.jsp&lt;/url-pattern&gt; &lt;scripting-invalid&gt;true&lt;/scripting-invalid&gt; &lt;/jsp-property-group&gt; &lt;/jsp-config&gt; </code></pre> <p>To learn more about EL, check the <a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnahq.html" rel="noreferrer">Java EE tutorial part II chapter 5</a>. Implicit EL objects, such as <code>${pageContext}</code> are described <a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnahq.html#bnaij" rel="noreferrer">here</a>. To learn more about JSTL, check the <a href="http://java.sun.com/javaee/5/docs/tutorial/doc/bnakc.html" rel="noreferrer">Java EE tutorial part II chapter 7</a>. Note that JSTL and EL are two separate things. JSTL is a <em>standard taglib</em> and EL just enables to access backend data programmatically. Although it is normally used in taglibs like JSTL, it can also be used standalone in template text.</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