snipt

Ctrl+h for KB shortcuts

Java Server Page

Breaking JSTL ForEach Loop

1
2
3
4
5
<c:forEach items="${items[id]}" var="doc" varStatus="status">
    <c:if test="${item.ready}">
        <c:set var="status.index" value="${items.size}"/>
    </c:if>
</c:forEach>
https://snipt.net/embed/ff9830b24164c4b59402fde646b352f4/
https://snipt.net/raw/ff9830b24164c4b59402fde646b352f4/
ff9830b24164c4b59402fde646b352f4
jsp
Java Server Page
5
2016-09-29T16:50:59
True
False
False
/api/public/snipt/66139/
breaking-jstl-foreach-loop
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="nt">&lt;c:forEach</span> <span class="na">items=</span><span class="s">&quot;${items[id]}&quot;</span> <span class="na">var=</span><span class="s">&quot;doc&quot;</span> <span class="na">varStatus=</span><span class="s">&quot;status&quot;</span><span class="nt">&gt;</span> </span><span id="L-2"><a name="L-2"></a> <span class="nt">&lt;c:if</span> <span class="na">test=</span><span class="s">&quot;${item.ready}&quot;</span><span class="nt">&gt;</span> </span><span id="L-3"><a name="L-3"></a> <span class="nt">&lt;c:set</span> <span class="na">var=</span><span class="s">&quot;status.index&quot;</span> <span class="na">value=</span><span class="s">&quot;${items.size}&quot;</span><span class="nt">/&gt;</span> </span><span id="L-4"><a name="L-4"></a> <span class="nt">&lt;/c:if&gt;</span> </span><span id="L-5"><a name="L-5"></a><span class="nt">&lt;/c:forEach&gt;</span> </span></pre></div> </td></tr></table>
jsp, jstl, loop

XML

JSTL: getting current URL

<c:out value="${pageContext.request.requestURL}"/>
https://snipt.net/embed/1bafed8f3234414b452373d0857b5628/
https://snipt.net/raw/1bafed8f3234414b452373d0857b5628/
1bafed8f3234414b452373d0857b5628
xml
XML
1
2016-09-30T03:10:31
True
False
False
/api/public/snipt/21199/
jstl-getting-current-url
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="nt">&lt;c:out</span> <span class="na">value=</span><span class="s">&quot;${pageContext.request.requestURL}&quot;</span><span class="nt">/&gt;</span> </span></pre></div> </td></tr></table>
jsp, jstl

Java Server Page

Servlet to jsp forward

1
2
3
String nextJSP = "/somepage.jsp";
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP);
dispatcher.forward(request,response);
https://snipt.net/embed/db25fe78ee7e683bfd4718c49b28af6b/
https://snipt.net/raw/db25fe78ee7e683bfd4718c49b28af6b/
db25fe78ee7e683bfd4718c49b28af6b
jsp
Java Server Page
4
2016-09-29T03:53:34
True
False
False
/api/public/snipt/13839/
servlet-to-jsp-forward
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a>String nextJSP = &quot;/somepage.jsp&quot;; </span><span id="L-2"><a name="L-2"></a>RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP); </span><span id="L-3"><a name="L-3"></a>dispatcher.forward(request,response); </span></pre></div> </td></tr></table>
forward, jsp, servlet

Java Server Page

tomcat startup shutdown

tomcatdirectory/bin/startup.sh
tomcatdirectory/bin/shutdown.sh
https://snipt.net/embed/21be09838362d7470361e1e99461da39/
https://snipt.net/raw/21be09838362d7470361e1e99461da39/
21be09838362d7470361e1e99461da39
jsp
Java Server Page
2
2016-09-28T19:02:25
True
False
False
/api/public/snipt/13817/
tomcat-startup-shutdown
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a>tomcatdirectory/bin/startup.sh </span><span id="L-2"><a name="L-2"></a>tomcatdirectory/bin/shutdown.sh </span></pre></div> </td></tr></table>
jsp, tomcat

XML

JSP if-else

1
2
3
4
5
6
7
<c:choose>
  <c:when test='${param.p == "someValue"}'>	
  </c:when>
  
  <c:otherwise> 	
  </c:otherwise>
</c:choose>
https://snipt.net/embed/c7466dd9b70e2eac04a7d0e4d98dc383/
https://snipt.net/raw/c7466dd9b70e2eac04a7d0e4d98dc383/
c7466dd9b70e2eac04a7d0e4d98dc383
xml
XML
7
2016-09-29T23:00:18
True
False
False
/api/public/snipt/11492/
jsp-if-else
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="nt">&lt;c:choose&gt;</span> </span><span id="L-2"><a name="L-2"></a> <span class="nt">&lt;c:when</span> <span class="na">test=</span><span class="s">&#39;${param.p == &quot;someValue&quot;}&#39;</span><span class="nt">&gt;</span> </span><span id="L-3"><a name="L-3"></a> <span class="nt">&lt;/c:when&gt;</span> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a> <span class="nt">&lt;c:otherwise&gt;</span> </span><span id="L-6"><a name="L-6"></a> <span class="nt">&lt;/c:otherwise&gt;</span> </span><span id="L-7"><a name="L-7"></a><span class="nt">&lt;/c:choose&gt;</span> </span></pre></div> </td></tr></table>
if-else, jsp, jstl
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.