【问题标题】:What is a best practice to pass data from Action to view(jsp) in Struts 1.3.?在 Struts 1.3 中将数据从 Action 传递到 view(jsp) 的最佳实践是什么?
【发布时间】:2013-01-31 02:47:15
【问题描述】:

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

我看到以下两种方法:

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

List<Employee>  employees;

设置该字段的动作类:

empForm.setEmployees(employeeList);

而 JSP 使用这些数据作为:

${empForm.employees}

2. 将员工列表直接放入请求中。

Action 类将employeeList 设置为请求。

request.setAttribute("employees", employeeList);

在 JSP 中:

${employees}

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

【问题讨论】:

    标签: jsp jakarta-ee web-applications struts struts-1


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-09-21
        • 1970-01-01
        • 2016-12-27
        • 2023-03-27
        • 2016-02-05
        • 1970-01-01
        • 2010-11-14
        • 2015-03-22
        相关资源
        最近更新 更多