<struts> tag
Root tag for the struts.xml
It may contain the tags : <package>, <include>, <bean> and <constant>
<package> tag
It groups actions, results, result types, interceptors, and interceptor-stacks into a logical configuration unit.
1. name
Mandatory attribute which is an unique name for the package.
It acts as the key for later reference to the package.
2. extends
Optional attribute which allows one package to inherit the configuration of one or more previous packages - including all interceptor, interceptor-stack, and action configurations.
All configuration information (including action configurations) from the extended package will be available in the new package, under the new namespace.
3. namespace
It provides a mapping from the URL to the package.
Example : For 2 different packages, with namespace attributes defined as "pack1" and "pack2", the URLs would be something like "/webApp/pack1/my.action" and "/webApp/pack2/my.action"
4. abstract
If this attribute value is "true" the package is truly a configuration grouping and actions configured will not be accessible via the package name.
It is important to make sure you are extending the correct parent package so that the necessary pre-configured features will be available to you.
<include> tag
This tag is used to modularize a Struts2 application that needs to include other configuration files.
It contains only one attribute "file" that provides the name of the xml file to be included.
This file has exactly the same structure as the "struts.xml" configuration file.
For example, to break a configuration file of a finance application, you might choose to group together the invoices, admin, report configurations etc into separate files.
<bean> tag
It requires the class attribute which specifies the Java class to be created or manipulated.
A bean can either be created by the framework's container and injected into internal framework objects, or have values injected to its static methods.
The first use, object injection, is generally accompanied by the type attribute, which tells the container that which interface this object implements.
The second use, value injection, is good for allowing objects not created by the container to receive framework constants. Objects using value inject must define the the static attribute.
1. class - Name of the bean class
2. type - Primary Java interface this class implements
3. name - Unique name of this bean; must be unique among other beans that specify the same type
4. scope - Scope of the bean; must be either default, singleton, request, session, thread
5. static - whether to inject static methods or not
<constant> tag
There are two key roles for constants :
1. They are used to override settings like the maximum file upload size or whether the Struts framework should be in devMode (development mode) or not.
2. They specify which Bean should be chosen, among multiple implementations of a given type.
Constants can be declared in multiple files.
By default, constants are searched for in the following order, allowing for subsequent files to override by the previous ones:
struts-default.xml > struts-plugin.xml > struts.xml > struts.properties > web.xml
No comments:
Post a Comment
Note: only a member of this blog may post a comment.