Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to avoid using scriptlets in my JSP page?
    text
    copied!<p>I've been told that the use of scriptlets (&lt;%= ... %>) in my JSP pages isn't such a great idea.</p> <p>Can someone with a bit more java/jsp experience please give me some pointers as to how to change this code so its more 'best practice', whatever that may be?</p> <p>This JSP is actually my sitemesh main decorator page. Basically my web design has a tab strip and a submenu, and i wish to somehow highlight the current tab and show the correct submenu by looking at the current request URI.</p> <pre><code>&lt;%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;My Events - &lt;decorator:title /&gt;&lt;/title&gt; &lt;link href="&lt;%= request.getContextPath() %&gt;/assets/styles.css" rel="stylesheet" type="text/css" /&gt; &lt;/head&gt; &lt;body&gt; &lt;div class="tabs"&gt; &lt;a &lt;%= request.getRequestURI().contains("/events/") ? "class='selected'" : "" %&gt; href='&lt;%= request.getContextPath() %&gt;/events/Listing.action'&gt;Events&lt;/a&gt; &lt;a &lt;%= request.getRequestURI().contains("/people/") ? "class='selected'" : "" %&gt; href='&lt;%= request.getContextPath() %&gt;/people/Listing.action'&gt;People&lt;/a&gt; &lt;/div&gt; &lt;div class="submenu"&gt; &lt;% if(request.getRequestURI().contains("/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;% } %&gt; &lt;% if(request.getRequestURI().contains("/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;% } %&gt; &amp;nbsp; &lt;/div&gt; &lt;div class="body"&gt; &lt;decorator:body /&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Thanks all</p>
 

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