Enabling JavaServerPages Standard Tag Library (JSTL) in JSP

JSTL support is dependent on the server/servletcontainer used. Some ships with JSTL, others don’t. This is regardless of the JSP/Servlet version. Usually, normal JEE servers such as WildFly/Payara/TomEE already ship with JSTL out the box, but barebones servletcontainers such as Tomcat/Jetty/Undertow don’t. For them you’ll need to install JSTL yourself. It’s actually pretty simple (assuming … Read more

c:forEach throws javax.el.PropertyNotFoundException: Property ‘foo’ not found on type java.lang.String

Here, <c:forEach var=”statusHistory” items=”statusHistoryList”> You’re supplying the items attribute of <c:forEach> with a plain vanilla String with a value of “statusHistoryList” which in turn indeed doesn’t have a getTimestamp() method. You need to reference it using an EL expression ${…} instead. <c:forEach var=”statusHistory” items=”${statusHistoryList}”> ${statusHistory.timestamp} </c:forEach>

How to evaluate a scriptlet variable in EL?

So you want to evaluate a scriptlet variable in EL? Store it as a request attribute. <% String var = “some”; request.setAttribute(“var”, var); %> <c:if test=”${param.variable1 == ‘Add’ && var == ‘some’}”> However, this makes no sense. You should avoid scriptlets altogether and use JSTL/EL to prepare this variable. So if you make the functional … Read more

How to call servlet through a JSP page

You could use <jsp:include> for this. <jsp:include page=”/servletURL” /> It’s however usually the other way round. You call the servlet which in turn forwards to the JSP to display the results. Create a Servlet which does something like following in doGet() method. request.setAttribute(“result”, “This is the result of the servlet call”); request.getRequestDispatcher(“/WEB-INF/result.jsp”).forward(request, response); and in … Read more

Include another JSP file

What you’re doing is a static include. A static include is resolved at compile time, and may thus not use a parameter value, which is only known at execution time. What you need is a dynamic include: <jsp:include page=”…” /> Note that you should use the JSP EL rather than scriptlets. It also seems that … Read more

if…else within JSP or JSTL

Should I use JSTL ? Yes. You can use <c:if> and <c:choose> tags to make conditional rendering in jsp using JSTL. To simulate if , you can use: <c:if test=”condition”></c:if> To simulate if…else, you can use: <c:choose> <c:when test=”${param.enter==’1′}”> pizza. <br /> </c:when> <c:otherwise> pizzas. <br /> </c:otherwise> </c:choose>

How to nest an EL expression in another EL expression

You can’t nest EL expressions like that. You can achieve the concrete functional requirement only if you know the scope of those variables beforehand. This way you can use the brace notation while accessing the scope map directly. You can use <c:set> to create a new string variable in EL scope composed of multiple variables. … Read more