作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我会尽量用几行来表达清楚,只显示基本代码。正如我在标题中所说,我必须将两个数组列表从 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");
此过程允许我将一个数组列表发送到 JSP 页面。如何发送两个不同的数组列表?例如,我需要发送这两个数组列表:
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>
关于java - 如何将两个不同的 ArrayList 从 Servlet 发送到 JSP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34484416/
我是一名优秀的程序员,十分优秀!