二维数组-会话

Two dimensional array- Session

我有一个二维矩阵,我想将其添加到 session。要将整数添加到 session 对象,语法是

session.setAttribute("Mat", mat); int matr = (Integer) session.getAttribute("Mat");

搜索了很多语法以将 int[][] 添加到 session。首先,我们可以补充一下,如果有的话,关于如何推进它有什么想法吗?

试试下面的:-

int[][] 2darr = new int[2][3];
session.setAttribute("2darr", 2darr );
int[][] 2darrFromSession = (int[][]) session.getAttribute("2darr");

您实质上是将对象添加到会话中。不管是整数还是二维整数数组...添加的语法应该相同

session.setAttribute("Mat", mat);

其中 mat 是一个二维整数数组

int mat[][] = new int[3][10]; //just an example

现在,去取它

int[][] ret = (int[][])session.getAttribute("Mat");

希望能奏效。