-1

here i'm setting data at students i want to print value from Arraylist to jsp page

this is servlet class

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

        studentDao =new StudentDao();
        List<Student> studentList=studentDao.display();

        request.setAttribute("students",studentList);
          for(Student stu:studentList){
            System.out.println(stu.getAge()+" " +stu.getStudentName());
        }
        RequestDispatcher requestDispatcher=getServletContext().getRequestDispatcher("/viewstudent.jsp");
        requestDispatcher.forward(request,response);
    }//method end

//this is jsp page

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>

<html>
<head>
    <title>view Student</title>
</head>
<body>
<table >
<c:forEach items="${students}" var="student">
    <tr>
        <td><c:out value="${student.roll_no}"></c:out></td>
    </tr>
    </c:forEach>
</table>
</body>
</html>
Purushottam
  • 149
  • 4
  • 17

1 Answers1

-1

getRequestDispatcher("/viewstudent.jsp?students="+studentList);

And on jsp just accept the value from the get method, e.g

List<Student> studentList = (List<Student>)request.getParameter("students")

Print it out like this;

<%for(int i = 0; i<student.size();i++){ out.print(sutudent.getName()); }

Just like that. The main point is passing the arrayList into the parameter of the link.

ElectronSz
  • 32
  • 1
  • 6