通过会话将 ArrayList 从一个 JSP 传递到另一个 JSP。

huangapple go评论71阅读模式
英文:

passing ArrayList from one JSP to another using session

问题

ArrayList<Object[]> custInfo = new ArrayList<Object[]>();
while(rs.next()){
    String loginId = rs.getString("LOGIN_ID");
    String  customerId = rs.getString("CUSTOMER_ID") ;
    String  requestDate = rs.getString("REQUEST_DATE") ;
    
    Object[] custInfo123 = {loginId, customerId, requestDate};
    custInfo.add(custInfo123);
}
session.setAttribute("custInfo", custInfo);

在一个名为retreivedata.jsp的 JSP 页面中,我使用了一个 ArrayList 来存储结果集的值,并设置了 session.setAttribute

在另一个名为 downloaddata.jsp 的 JSP 页面中,我使用了以下代码:

ArrayList<Object[]> custInfo = (ArrayList<Object[]>) session.getAttribute("custInfo");

但是这给了我一个错误,错误信息是 "ArrayList 无法解析为一种类型"。

英文:
          ArrayList&lt;Object[]&gt; custInfo = new ArrayList&lt;Object[]&gt;(); 
			while(rs.next()){
				String loginId = rs.getString(&quot;LOGIN_ID&quot;);
		    	String  customerId = rs.getString(&quot;CUSTOMER_ID&quot;) ;
		    	String  requestDate = rs.getString(&quot;REQUEST_DATE&quot;) ;
		    	
		    	 Object[] custInfo123 = {loginId, customerId, requestDate};
		    	 custInfo.add(custInfo123);
		}
			 session.setAttribute(&quot;custInfo&quot;, custInfo);

in one jsp retreivedata.jsp im using arraylist to store values of result set and set session.setAttribute.
and in other jsp downloaddata.jsp im using,

ArrayList&lt;Object[]&gt; custInfo = (ArrayList&lt;Object[]&gt;)session.getAttribute(&quot;custInfo&quot;);

but it has given me error ArrayList can not be resolved to a type.

答案1

得分: 1

Add import statement for ArrayList.

import java.util.ArrayList;

Update

For importing ArrayList in JSP, use the following syntax:

<%@ page import="java.util.ArrayList" %>
英文:

Add import statement for ArrayList.

import java.util.ArrayList;

Update

For importing ArrayList in jsp, use following syntax:

&lt;%@ page import=&quot;java.util.ArrayList&quot; %&gt;

huangapple
  • 本文由 发表于 2020年9月29日 13:46:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/64113589.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定