5

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.

Nils
  • 806
  • 1
  • 9
  • 24

2 Answers2

2

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.

zawhtut
  • 8,335
  • 5
  • 52
  • 76
0

If you need to edit data it's better to put it to action form otherwise there is no big difference.

Alex
  • 11,451
  • 6
  • 37
  • 52