Here is my current situation: I created a Maven project from my shell using the following command:
mvn archetype:generate -DgroupId=it.my.current.package.example -DartifactId=Example -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
mvn package
Then I opened Eclipse, imported the project as Maven. I added these dependencies to my
pom.xml
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>provided</scope>
</dependency>
Then I created a JSP and a servlet.
My servlet just sets some variables, and my JSP uses them with some JSTLs.
I added this tag to my JSP:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
and my JSP code is very simple:
<c:forEach items="${requestScope.empList}" var="emp">
<tr>
<td><c:out value="${emp.id}"></c:out></td>
<td><c:out value="${emp.name}"></c:out></td>
<td><c:out value="${emp.role}"></c:out></td>
</tr>
</c:forEach>
My servlet does this:
List<Employee> empList = new ArrayList<Employee>();
Employee emp1 = new Employee();
emp1.setId(1); emp1.setName("Sam");emp1.setRole("Developer");
Employee emp2 = new Employee();
emp2.setId(2); emp2.setName("John");emp2.setRole("Manager");
empList.add(emp1);empList.add(emp2);
request.setAttribute("empList", empList);
RequestDispatcher rd = getServletContext().getRequestDispatcher("/home.jsp");
rd.forward(request, response);
An employee is a simple bean.
When I try to run this application from my servlet, it actually shows me this on my JSP:
${emp.id} ${emp.name} ${emp.role}
And it does not show the value that I set on my Servlet.
I am completely new to JSTL, so I entered my problem first. I tried adding jstl-1.2.jarto my directory $TOMCAT_HOME/lib, but that didn't work.
?
EDIT: , JSTL? , ?