How to iterate an ArrayList inside a HashMap using JSTL?

You can use JSTL <c:forEach> tag to iterate over arrays, collections and maps. In case of arrays and collections, every iteration the var will give you just the currently iterated item right away. <%@ taglib prefix=”c” uri=”http://java.sun.com/jsp/jstl/core” %> <c:forEach items=”${collectionOrArray}” var=”item”> Item = ${item}<br> </c:forEach> In case of maps, every iteration the var will give … Read more

How to use if, else condition in jsf to display image

For those like I who just followed the code by skuntsel and received a cryptic stack trace, allow me to save you some time. It seems c:if cannot by itself be followed by c:otherwise. The correct solution is as follows: <c:choose> <c:when test=”#{some.test}”> <p>some.test is true</p> </c:when> <c:otherwise> <p>some.test is not true</p> </c:otherwise> </c:choose> You … Read more

JSTL vs JSP Scriptlets

You seem to concentrate on only the presentation and flow-control part of the scriptlets as in using if, for and switch statements and out.print() things. You seem to compare scriptlets 1:1 with JSTL. This is wrong. I was not talking about the flow control part only (which is indeed to be replaced by JSTL), but … Read more

Accessing a JSTL / EL variable inside a Scriptlet

JSTL variables are actually attributes, and by default are scoped at the page context level. As a result, if you need to access a JSTL variable value in a scriptlet, you can do so by calling the getAttribute() method on the appropriately scoped object (usually pageContext and request). resp = resp + (String)pageContext.getAttribute(“test”); Full code … Read more

What is the difference between and ?

<c:if is a simple if-clause. <c:when> has options for multiple if-clauses and an else clause. Compare: <c:if test=”${foo == ‘bar’}”>…</c:if> with <c:choose> <c:when test=”${foo == ‘bar’}”>…</c:when> <c:when test=”${foo == ‘baz’}”>…</c:when> <c:otherwise>…</c:otherwise> </c:choose>

What is the best way to create JSP layout template? [duplicate]

Put the following in WEB-INF/tags/genericpage.tag <%@tag description=”Overall Page template” pageEncoding=”UTF-8″%> <%@attribute name=”header” fragment=”true” %> <%@attribute name=”footer” fragment=”true” %> <html> <body> <div id=”pageheader”> <jsp:invoke fragment=”header”/> </div> <div id=”body”> <jsp:doBody/> </div> <div id=”pagefooter”> <jsp:invoke fragment=”footer”/> </div> </body> </html> To use this: <%@page contentType=”text/html” pageEncoding=”UTF-8″%> <%@taglib prefix=”t” tagdir=”/WEB-INF/tags” %> <t:genericpage> <jsp:attribute name=”header”> <h1>Welcome</h1> </jsp:attribute> <jsp:attribute name=”footer”> <p id=”copyright”>Copyright … Read more

How to set the JSTL variable value in javascript?

It is not possible because they are executed in different environments (JSP at server side, JavaScript at client side). So they are not executed in the sequence you see in your code. var val1 = document.getElementById(‘userName’).value; <c:set var=”user” value=””/> // how do i set val1 here? Here JSTL code is executed at server side and … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)