2017-04-03 5 views
0

Wie man diesen in Java geschriebenen Code in jstl-Tags in einer JSP-Seite umwandelt. Ich möchte dies auf einer JSP-Seite drucken. DankWie drucke ich eine Liste mit JSTL in JSP-Seite?

<% 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()); 

    } 

Antwort

0

eine jsp Seite und ein Servlet wie diese erstellen.

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); 
} 

und 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> 

Ich hoffe, dies wird Ihnen helfen :)

Verwandte Themen