开发者

Best way to get the data from Action subclass to Jsp View?

开发者 https://www.devze.com 2023-02-13 04:14 出处:网络
I am trying to pass a list of some data by storing each item\'s data in a HashMa开发者_开发知识库p and then storing all the HashMaps in a ArrayList and then passing it to the request object to the Vie

I am trying to pass a list of some data by storing each item's data in a HashMa开发者_开发知识库p and then storing all the HashMaps in a ArrayList and then passing it to the request object to the 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.


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

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

Please let me know if its working.

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


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.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消