How many values ​​are available for the scope attribute in the action element of struts-config.xml file

How many values ​​are available for the "scope" attribute in the "action" struts-config.xml file other than a "request" and a "session"?

 <action name="loginform" path="/bkplogin" scope="?" type="org.springframework.web.struts.DelegatingActionProxy"> 
+7
source share
1 answer

There are only two possible values for the scope attribute: the request and the session , as indicated in the DTD configurations:

 <!-- 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 DTD here:
http://struts.apache.org/dtds/struts-config_1_3.dtd

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

How about "App" and "Page"?

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

  • page - access to the object is possible only from the same JSP page in which it was created;
  • request - objects created using the request area can be accessed from any pages serving this request;
  • session - the object is accessible from pages belonging to the same session (it covers several requests of the same client, with the state preserved in the session, each client with its own session);
  • application - objects from this area can be accessed from any pages in the application (all users use the same objects in the application area, one object for all users).

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

It does not make sense to have a form with a scope, because it will be one form for everyone, which I can’t even think that it will be useful. Therefore, no application value for this field.

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

Thus, there are only two values: request and session . If you need something extra, you need to manage it yourself.

Struts is a general framework; it does not cover all conceivable or unimaginable cases; it covers most normal use cases for which a query and session is all that you will ever need.

+9
source

All Articles