Tech notes for java-jstl



  1. JSP: If else in JSTL
  2. JSP: Setup JSTL and EL in Tomcat 7

JSP: If else in JSTL

And if statement in JSTL is:

<c:if test="${true}">

And if-else is actually choose-when-otherwise:

	<c:when test="${true}">

Don't forget to include the jstl taglib.

java-jsp java-jstl java

JSP: Setup JSTL and EL in Tomcat 7

If you want to use JSTL (and you do) instead of scriptlets you first have to include it in your war file or your tomcat lib file.

I imported it into my project using Gradle. You should see the jar file in the created WAR file once you're using it.

Now you can use things like:

<%@ taglib uri="" prefix="c" %> 
<c:forEach var="p" items="${applicationScope['products'].values().iterator()}">

	${} | ${p.getPrice()} || <a href="Cart?add=true&id=${p.getId()}">add</a>
	<br />


Note you don't need the scriptlet %@ page import.. directives anymore. You do need thee taglib directive to point to the jstl core library.

Note we're using the JSP EL, expression language, syntax to call method and attribute ( is the same as p.getName()). EL comes with Tomcat 7 - no additional libraries are required.

As with scriplets there are implicit objects in EL, applicationScope, in this example. 'applicationScope['products'] is the same as applicationScope.getAttribute('products').

java-jsp java-jstl java-tomcat java

Page 1 of 1
Click me