How to loop over HashMap in JSP using JSTL? Example
Though there are a number of ways to loop over a HashMap in JSP, or any other Map implementation e.g. Hashtable, I personally prefer the JSTL foreach tag for iteration over HashMap in JSP. As a Java programmer, you will often have a strong urge to use Java code directly in JSP using scriptlet, but that's a bad coding practice and one should always avoid that. In fact, by smart use of expression language and JSTL core tag library, you can reduce a lot of Java code from your JSP page. In our last post, we have seen an example of JSTL foreach tag to loop over List, but not a HashMap, and that creates a doubt in one of my readers mind that foreach tag doesn't support Map implementation like HashMap or Hashtable as they are not Collection, but that's not true.
تعليقات
إرسال تعليق