Struts.XML Configuration file is used to map the Action class in view pages.
[xml]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="default" extends="struts-default">
<action name="Hello" class="com.splesson.SPlessonsAction">
<result name="success">/HelloWorld.jsp</result>
</action>
</package>
</struts>
[/xml]
- DOCTYPE is used, to map the struts tags in the configuration file.
- One have to write the struts application is some modules, then all modules are configured the one configuration file, at that time package element is used in struts.XML file.
Package element contain some attributes like
name,
namespace and
extend.
Name: It specifies the package name. By default, it as the default package name.
package name="default"
Namespace: It specifies the action class location or uri, It is not mandatory in struts.XML file. The container will take the default namespace uri */.action.
Extends: It is used, whenever one extended any class or implements any interface, at that time the extends is used. The container will take the default package struts-default.
3.
action element is defined as the action class properties. It contains three attributes like name, class and method. an action tag writes under the package tag.
Name: It specifies the action name. A container will check the JSP page action name and action class name is same or not.
action name="Hello"
Class: It is defined as action class name with fully qualified name (package name and class name). A container will check the mapped action class. If action classes matched then execute() method is executed.
action name="action" class="com.itoolsinfo.ActionClass"
Method: It is the optional attribute. When one execute the specific method in Action class. The method attribute is defined in action tag. for example, when the execute() method in Action class defined, It will be executed manually and defined the method= method name.
actionname="myAction"Class="com.itoolsinfo.MyActionClass"method="post"
4.
result element is defined as the after execute the execute() method, The container will check, where one want to store that result. It is the sub tag of action class tag.
result element is contained name and value.
Name: Every result contain some specific name and it can map the execute() method return value.
The container will take the default name is a success.
result name="success"
Type: It is optional. It will check whether JSP page response is displayed on a browser.
result name="success">HelloWorld.jsp
Then HelloWorld.jsp page response will be printed on browser.
In struts application, one need to configure the multiple configuration files in classes folder. Classes folder doesn't create the default in eclipse IDE, one need to create a classes folder in WEB-INF folder.