5

我正在用struts 1.3编写 web 应用程序。我想将员工的 ArrayList 传递给 JSP 页面。

我看到以下两种方法:

1. 将员工列表作为字段放入 ActionForm。

List<Employee>  employees;

设置此字段的操作类:

empForm.setEmployees(employeeList);

并且 JSP 使用这些数据作为:

${empForm.employees}

2. 将员工名单直接放入请求中。

操作类将employeeList 设置为请求。

request.setAttribute("employees", employeeList);

在 JSP 中:

${employees}

请建议我应该采用哪种方法。在Struts 1.3中哪一个被认为是一个好的实践。

4

2 回答 2

2

两者都是正确的。如果页面需要表单,您可以将列表放在 ActionForm 中。我个人更喜欢在 ActionForm 中设置,因为它更有条理。

于 2013-02-15T09:08:10.847 回答
0

如果您需要编辑数据,最好将其付诸行动,否则没有太大区别。

于 2013-02-15T13:20:53.630 回答