2

I went through a number of links regarding this exception. I don't know whether the action class has a problem or the jsp.

My DAO is:

         {
            ReleaseData releaseData = new ReleaseData();
            releaseData.setRollno(resultSet.getInt("rollno"));
            releaseData.setName(resultSet.getString("name"));
            releaseData.setAge(resultSet.getInt("age"));
            myDataList.add(releaseData);
            System.out.println("the List has---"+myDataList);
        }

And my Servlet is:

            public class DisplayServlet extends HttpServlet
          {
                public void doGet(HttpServletRequest request ,HttpServletResponse  response) throws ServletException,IOException
{
    List<ReleaseData> myDataList = new ReleaseDataDAO().getReleaseData();
    request.setAttribute("myDataList", myDataList);
    request.getRequestDispatcher("/showData.jsp").forward(request, response);
}
}

And here is my jsp:

<c:forEach items="$(myDataList)" var="data">
             <tr>
               <td>${data.rollno}</td>
                 <td>${data.name}</td>
                <td>${data.age}</td>

              </tr>
             </c:forEach>
danday74
  • 52,471
  • 49
  • 232
  • 283
Mayur Sawant
  • 39
  • 1
  • 2
  • 5

1 Answers1

3

Hmmm I've just noticed, you are using $() instead of ${}, jsp is not jQuery :P this $(myDataList) is not being interpreted as an EL expression and becoming a String, do this instead: ${myDataList}

Also:

You need to create the getter and setter methods, in the code you provided I could see a set method to rollno but no get method, also they must be public

public class ReleaseData{
    private int rollno = 0;
    private String name = "";
    private int age = 0;

    public int getRollno(){ return rollno; }
    public void setRollno(int rollno){ this.rollno = rollno; }

    public int getAge(){ return age; }
    public void setAge(int age){ this.age= age; }

    public String getName(){ return name; }
    public void setName(String name ){ this.name = name; }

}

Also, it's always nice to escape any data that can be entered by a human.

<c:forEach items="${myDataList}" var="data">
 <tr>
   <td><c:out value="${data.rollno}" /></td>
     <td><c:out value="${data.name}" /></td>
    <td><c:out value="${data.age}" /></td>

  </tr>
 </c:forEach>
Polyana Fontes
  • 3,156
  • 1
  • 27
  • 41