0

How to transform this code written in java into jstl tags in a JSP page. I want to print this on a JSP page. Thanks

<% List<?> currentUserList = (List<?>)(session.getAttribute("currentSessionUser"));%>
     for(int i=0; i<currentUserList.size(); i++) {
                Object[] row = (Object[]) currentUserList.get(i);
                ContUser cont = (ContUser)row[0];
                Emp emp= (Emp)row[1];
                System.out.println("Cont ID:"+cont.getIdCont()+", USER:"+ cont.getUser()+ ", Emp ID:"+ emp.getIdEmp()+", Name:"+ emp.getName());

     }
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Taylor
  • 33
  • 3
  • 8

1 Answers1

0

create a jsp page and a servlet like this.

public class MyServlet extends HttpServlet {

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
   HttpSession session=req.getSession();
   session.setAttribute(currentUserList);
   this.getServletContext().getRequestDispatcher("/test.jsp").forward(req, resp);
}

and test.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<c:forEach items="${currentUserList}" var="i" varStatus="status">
       count ${status.count} index: ${status.index} current:      ${status.current} first: ${status.first} last: ${status.last} item: ${i}<br>
</c:forEach>

</body>
</html>

I hope this will help you :)

Rafik
  • 395
  • 1
  • 2
  • 12