gpt4 book ai didi

java - JSF Controller 与 Struts Controller

转载 作者:搜寻专家 更新时间:2023-11-01 03:54:22 25 4
gpt4 key购买 nike

我在某处读到

Developer can access the struts controller by creating an Action object that can integrate with the controller whereas Java Server Faces technology does not allow access to the controller.

谁能为我详细说明一下,这是什么意思?任何例子都会有很大的帮助。

还有

The Struts controller can do things like access control on each Action based on user roles. This functionality is not provided by JSF.

这个我也很疑惑。请举例说明这一点。

最佳答案

当您为 Struts 2 编写代码时(对于 Struts 也是如此),您是在 Controller 本身扩展框架。 Action 是您使用自己的操作扩展的基类,它允许您扩展 Controller 逻辑,通常是通过对业务逻辑进行一些调用,然后重定向到您的结果 View 之一(在s2 ) 基于该逻辑的结果。当然,您可以对操作执行访问控制之类的操作;但是你可以对一个 Action 做任何事情。我想这段引述只是指出 Struts 2 的概念粒度与 Action (controller) 的每个请求实例同步。

至于 JSF,它是一种完全不同类型的框架。它不是像 Struts 2 那样面向“请求”,而是“面向组件”。这意味着 JSF 的概念粒度是页面上组件小部件的概念。这在某种程度上与 struts 2 处理单个请求的方式不同,或者可能是正交的。因此,在 JSF 中,框架更深入地隐藏了 Controller 逻辑,主要是因为它更复杂。 Controller 逻辑必须从请求中获取传入数据,并确保将其映射并传送到与请求关联的页面上的适当组件小部件。开发人员 api 都是关于组件契约(Contract)的。

关于java - JSF Controller 与 Struts Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13348096/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com