I am running a very first foreach loop in jsp. I dont know what the problem is. Its not showing any errors as well.
This is my java code:
package pack1;
import java.util.ArrayList;
public class jstlClass
{
String emp_name;
String emp_id;
String emp_dept;
public String getEmp_name()
{
return emp_name;
}
public void setEmp_name(String emp_name)
{
this.emp_name = emp_name;
}
public String getEmp_id()
{
return emp_id;
}
public void setEmp_id(String emp_id)
{
this.emp_id = emp_id;
}
public String getEmp_dept()
{
return emp_dept;
}
public void setEmp_dept(String emp_dept)
{
this.emp_dept = emp_dept;
}
public static void main(String[] gs)
{
ArrayList li=new ArrayList();
jstlClass emp=new jstlClass();
emp.setEmp_id("20");
emp.setEmp_name("vishnu");
emp.setEmp_dept("it");
li.add(emp);
jstlClass j=new jstlClass();
j.setEmp_id("21");
j.setEmp_name("prem");
j.setEmp_dept("csc");
li.add(j);
}
}
This is my jsp code:
<html>
</head>
<body>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<jsp:useBean id="emp1" class="pack1.jstlClass" scope="session"/>
<%@ page import="java.util.*" %>
<%
<c:forEach var="li" items="${sessionScope.li}">
<c:out value="${li.emp_id}"/>
<c:out value="${li.emp_name}"/>
<c:out value="${li.emp_dept}"/>
</c:forEach>
%>
</body>
</html>
I have tried for so long but still it shows the same output. I am using Eclipse and Apache Tomcat server. I even tried running it in google chrome server, but no changes. I have put that "Hello world" in there and its displaying that, but not entering the foreach loop. This is my first foreach loop program and i have absolutely no idea what is going wrong. Help please!