struts-config.xml 文件的action 元素中的scope 属性有多少个可用值

发布于 2024-10-13 00:55:45 字数 244 浏览 0 评论 0原文

有多少个值可用于“action”元素中的“scope”属性 struts-config.xml 文件除了“request”和“session”之外?

<action name="loginform" path="/bkplogin" scope="?" type="org.springframework.web.struts.DelegatingActionProxy">

How many values available for "scope" attribute in "action" element of
struts-config.xml file other than "request" and "session"?

<action name="loginform" path="/bkplogin" scope="?" type="org.springframework.web.struts.DelegatingActionProxy">

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猫卆 2024-10-20 00:55:45

作用域属性只有两个可能的值请求会话,如struts-config的DTD中所述:

<!-- 
The name of a JSP bean scope within which such a form bean may be accessed.
-->
<!ENTITY % RequestScope "(request|session)">
...
...
<!ATTLIST action   scope    %RequestScope;  #IMPLIED>

请参阅此处的DTD:< br>
http://struts.apache.org/dtds/struts-config_1_3.dtd

或者这里有更易于阅读的 DTD 文档:
http://struts.apache.org/1 .x/struts-core/dtddoc/struts-config_1_3.dtd#action

“应用程序”和“页面”怎么样?

那么,跨 JSP 页面的对象范围可以是:

  • page - 只能从创建该对象的同一个 JSP 页面内访问该对象;
  • 请求 - 使用请求范围创建的对象可以从服务该请求的任何页面访问;
  • session - 可以从属于同一会话的页面访问对象(跨越同一客户端的多个请求,状态在会话中维护,每个客户端都有自己的会话);
  • 应用程序 - 可以从应用程序中的任何页面访问此范围内的对象(所有用户在应用程序范围内共享相同的对象,一个对象适用于所有用户)。

现在,struts-config 中的范围指的是创建/查找 ActionForm 对象的位置。 ActionForm 代表客户端 HTML 表单的服务器对象表示。

拥有具有应用范围的表格没有任何意义,因为它将是适合每个人的一种表格,我什至无法想象它会有什么用处。所以该领域没有应用价值。

现在假设您有页面范围。这将如何运作? Struts 执行 RequestDispatcher.forward/redirect 转到JSP 文件,如何将 ActionForm 保存在仍然没有页面范围的页面的页面范围中,因为它还没有控制权?!就像向方法发送值一样,但您不是发送方法参数,而是尝试从方法外部直接在方法代码中创建局部变量。

因此只有两个值有意义:请求会话。如果你想要额外的东西,你必须自己管理。

Struts 是一个通用框架,它并没有涵盖所有可以想象或难以想象的情况,它涵盖了大多数正常用例场景,其中请求和会话就是您所需要的。

There are only two possible values for the scope attribute: request and session as stated in the struts-config’s DTD:

<!-- 
The name of a JSP bean scope within which such a form bean may be accessed.
-->
<!ENTITY % RequestScope "(request|session)">
...
...
<!ATTLIST action   scope    %RequestScope;  #IMPLIED>

See the DTD here:
http://struts.apache.org/dtds/struts-config_1_3.dtd

or a more human readable documentation of the DTD here:
http://struts.apache.org/1.x/struts-core/dtddoc/struts-config_1_3.dtd#action

What about the "Application" and "page" ?

Well, the scope of an object across JSP pages can be:

  • page - an object can be accessed only from within the same JSP page it was created in;
  • request - objects created using the request scope can be accessed from any pages that serves that request;
  • session - an object is accessible from pages that belong to the same session (spans across multiple requests of the same client, with state maintained in the session, each client with his own session);
  • application - objects from this scope can be accessed from any pages in the application (all users share the same objects in application scope, one object to all users).

Now, the scope in struts-config refers to where to create/find ActionForm objects. An ActionForm represents the server object representation of a client HTML form.

It does not make any sense to have the form with application scope because it will be one form for everybody which which I can't even think at what that will be useful. So no application value for that field.

Now imagine you have page scope. How will that work? Struts does a RequestDispatcher.forward/redirect to go to the JSP files, how is it going to save the ActionForm in the page scope of the page that still does not have a page scope since it does not yet have control?! Is just like sending values to a method but instead of sending method arguments you are trying to directly create local variables in the code of the method from outside the method.

So there are only two values that make sense: request and session. If you want something extra you have to manage it yourself.

Struts is a generic framework, it does not cover every imaginable or unimaginable case, it covers most of normal use case scenarios for which request and session is all you will ever need.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文