• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to get jstl working

 
Harish Yerneni
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ref page 437 example from HFSJ. My output is just movielist and no movies listed after that. can someone please help me.

Here is my code from the servlet

public class cforeach extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException{


String[] movieList = {"Amelie", "Return of the king", "Mean Girls"};
request.setAttribute("movieList", movieList);

RequestDispatcher view = request.getRequestDispatcher("testjstl.jsp");
view.forward(request, response);

}

}

My code from the JSP is

<%@ taglib prefix ="c" uri = "http://java.sun.com/jsp/jstl/core" %>

<html>

<body>
<%@ page isELIgnored="false" %>

<strong> Movie List </strong>
<br> <br>

<table>

<c:forEach var="movie" items="${movieList}">

<tr>

<td>${movie}</td>

</tr>
</c:forEach>

</table>

</body></html>
 
Amit Saini
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried out your code as it as and it works for me.

Output:
Movie List

Amelie
Return of the king
Mean Girls

I dont see anything wrong with the code.
 
Harish Yerneni
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Amit. Instead of accessing the servlet from the browser, I was accessing the jsp directly. Thats why, the browser could not see the request object.

Thanks,

Harish
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic