Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a best practice to pass data from Action to view(jsp) in Struts 1.3.?

I am writing web application in struts 1.3. I want to pass ArrayList of Employees to JSP page.

I see following two approches :

1. Put List of Employee as a field into ActionForm.

List<Employee>  employees;

Action class setting this field:

empForm.setEmployees(employeeList);

And JSP using this data as :

${empForm.employees}

2. Put the list of Employees directly into request.

Action class setting employeeList into request.

request.setAttribute("employees", employeeList);

And in JSP:

${employees}

Please suggest what approach should I go with. Which one is considered to be a good practice in Struts 1.3.

like image 505
Nils Avatar asked Nov 04 '22 04:11

Nils


1 Answers

Both are correct. If the page required form you can put the list in the ActionForm. Personally I prefer setting inside ActionForm since it is more organized.

like image 120
zawhtut Avatar answered Nov 10 '22 16:11

zawhtut