繁体   English   中英

如何将两个不同的ArrayList从Servlet发送到JSP

[英]How to send two different ArrayList from a Servlet to a JSP

我将尝试在几行中弄清楚,仅显示基本代码。 就像我在标题中所说的那样,我必须将两个数组列表从servlet发送到JSP页面。 不幸的是,我不知道如何向JSP发送多个数组列表,但是我只知道发送一个数组列表。 我通常使用以下过程:

ArrayList<ClassA> array_A = new ArrayList<ClassA>();

// [...] After some operations and have filled the array_A with objects of class ClassA

ServletContext sc = request.getSession().getServletContext();
request.setAttribute("Attribute", array_A);
RequestDispatcher rd = sc.getRequestDispatcher("/MyJSP.jsp");
rd.forward(request,response);
request.getSession().removeAttribute("Attribute");

此过程使我可以将一个arraylist发送到JSP页面。 如何发送两个不同的arraylist? 例如,我需要发送这两个arraylist:

ArrayList<ClassA> array_A = new ArrayList<ClassA>();
ArrayList<ClassB> array_B = new ArrayList<ClassB>();

// [...] After some operations and have filled array_A with objects of class ClassA 
// & array_B with objects of class ClassB

如何将这两个数组从servlet发送到JSP页面? 您能和我分享代码吗? 如果我不那么严格,我很抱歉。

request.setAttribute("array_A", array_A);
request.setAttribute("array_B", array_B);

jsp (使用jstl核心库时,使用前缀c

<c:forEach var="itemA" items="${array_A}">
      <!-- some code here -->
</c:forEach>

<c:forEach var="itemB" items="${array_B}">
      <!-- some code here -->
</c:forEach>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM