What is the best practice for transferring data from Action for viewing (jsp) in Struts 1.3.?

I am writing a web application in struts 1.3 . I want to pass ArrayList employees to the JSP page.

I see the following two statements:

1. Place the employee list as a field in ActionForm.

List<Employee> employees; 

The action class that defines this field:

 empForm.setEmployees(employeeList); 

And JSP using this data as:

 ${empForm.employees} 

2. Put the list of employees directly in the request.

A class action that sets employeeList to the request.

 request.setAttribute("employees", employeeList); 

And in JSP:

 ${employees} 

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

+4
source share
2 answers

Both are correct. If a page form is required, you can put this list in an ActionForm. Personally, I prefer to install inside an ActionForm as it is more organized.

+1
source

If you need to edit the data, it is better to put them in the action form, otherwise there is not much difference.

0
source

All Articles