从Action子类获取数据到Jsp View的最佳方法?

时间:2021-05-29 11:27:06

I am trying to pass a list of some data by storing each item's data in a HashMap and then storing all the HashMaps in a ArrayList and then passing it to the request object to the View.

我试图通过将每个项目的数据存储在HashMap中,然后将所有HashMaps存储在ArrayList中,然后将其传递给View的请求对象来传递一些数据列表。

Can anybody tell me a better way to do so!

任何人都可以告诉我一个更好的方法!

One more thing I would like to add is that sometimes the data I want to put first is null and so the ArrayList size becomes zero.

我想补充的另一件事是,有时我想先放入的数据是null,因此ArrayList大小变为零。

2 个解决方案

#1


0  

Have the below code in ActionClass as below
request.setAttribute("ItemsList",ItemsList);//set it in request scope

在ActionClass中有以下代码,如下所示request.setAttribute(“ItemsList”,ItemsList); //在请求范围内设置它

and fetch it in the coressponding jsp page by using the below snippet
request.getAttribute("ItemsList"); //get it via request scope

并使用下面的代码片段request.getAttribute(“ItemsList”)在coressponding jsp页面中获取它; //通过请求范围获取它

Please let me know if its working.

如果它正常工作,请告诉我。

Possible alternate solution is to iterate the list using the <logic:iterate> struts tag.

可能的替代解决方案是使用 struts标记迭代列表。

#2


0  

There is another approach also :

还有另一种方法:

As you said you are putting all the hashmap data into the list, first do one thing. Put that list as a field into the ActionForm. After that set that list from the action class. for example if you have the employees you will have the method like setEmployees(). So you can set the list as empForm.setEmployees(employeeList); and all this will be in your action class.

正如您所说,您将所有hashmap数据放入列表中,首先要做一件事。将该列表作为字段放入ActionForm中。之后,从动作类中设置该列表。例如,如果你有员工,你将拥有像setEmployees()这样的方法。所以你可以将列表设置为empForm.setEmployees(employeeList);所有这些都将在你的动作类中。

Next, form jsp page you can retrieve the values as ${empForm.employees}

接下来,在表单jsp页面中,您可以将值检索为$ {empForm.employees}

#1


0  

Have the below code in ActionClass as below
request.setAttribute("ItemsList",ItemsList);//set it in request scope

在ActionClass中有以下代码,如下所示request.setAttribute(“ItemsList”,ItemsList); //在请求范围内设置它

and fetch it in the coressponding jsp page by using the below snippet
request.getAttribute("ItemsList"); //get it via request scope

并使用下面的代码片段request.getAttribute(“ItemsList”)在coressponding jsp页面中获取它; //通过请求范围获取它

Please let me know if its working.

如果它正常工作,请告诉我。

Possible alternate solution is to iterate the list using the <logic:iterate> struts tag.

可能的替代解决方案是使用 struts标记迭代列表。

#2


0  

There is another approach also :

还有另一种方法:

As you said you are putting all the hashmap data into the list, first do one thing. Put that list as a field into the ActionForm. After that set that list from the action class. for example if you have the employees you will have the method like setEmployees(). So you can set the list as empForm.setEmployees(employeeList); and all this will be in your action class.

正如您所说,您将所有hashmap数据放入列表中,首先要做一件事。将该列表作为字段放入ActionForm中。之后,从动作类中设置该列表。例如,如果你有员工,你将拥有像setEmployees()这样的方法。所以你可以将列表设置为empForm.setEmployees(employeeList);所有这些都将在你的动作类中。

Next, form jsp page you can retrieve the values as ${empForm.employees}

接下来,在表单jsp页面中,您可以将值检索为$ {empForm.employees}