Search code examples
javajspservletsjstl

<c:foreach> to show list


i have a list:

 private static List<Flower> flower = new ArrayList<>();

i am add value to it from xml with DOMParser like this:

 String idValue = eElement.getAttribute("id");
                        flower.setId(idValue);
                        String nameValue = eElement.getAttribute("name");
                        flower.setName(nameValue);

So, when i send my list to command line i see that list have all my value from xml. But when i am trying to send my list with request from jsp in servlet, doesn't show something. index.jsp - in this form i launch the app, have just one button with get method:

   <form action="DOMParserServlet" method="GET" > 
          <input type="submit" value="Execute">
               </form>  

than he goes to servlet. my servlet get method code, i am trying to set list for request and forward request to new page after processing:

DOMParser.XMLParser("C:/Users/admin/workspace/WebParser/Flower.xml");
     response.setContentType("text/html"); 
     request.setAttribute("flowers", Flowers.getFlowerList());
     request.getRequestDispatcher("/tableView.jsp").forward(request, response);

than i need to forward servlet answer to tableView.jsp to show my list in the form.
my tableView.jsp code:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert </title>
</head>
<body>
<h1>tableview</h1>
<c:forEach items="${flowers}" var="item">
    ${item}<br>
</c:forEach>
</body>
</html>

Solution

  • So i found the mistake. i am create a new instance of a class with empty list. that's why my jsp didn't show my list.