<struts> <package name="action" namespace="/action" extends="struts-default"> <action name="LoginAction" class="action.LoginAction" method="execute"> <result name="teacher">/teacher.jsp</result> <result name="student">/student.jsp</result> <result name="error">/error.jsp</result> </action> </package> <include file=""></include> </struts>
Common namespace /, or / package name.
When large xml file can be used to configure multiple xml file, such as using a configuration of this package to xml action in each packet, in the structs.xml <include> xml configuration file contains the other can come .
A method of setting processing request
<package name="action" namespace="/action" extends="struts-default">
<global-allowed-methods></global-allowed-methods>
<action name="loginAction" class="action.LoginAction" method="exe">
<allowed-methods></allowed-methods>
</action>
</package>
Using method attribute set in the <action> may be provided at <allowed-methods> </ allowed-methods> may also be provided throughout the package <global-allowed-methods> </ global-allowed-methods> in of.
Since it is the methods, the plural form, you can set up multiple method names.
structs-default.xml configuration:
<global-allowed-methods>execute,input,back,cancel,browse,save,delete,list,index</global-allowed-methods>
Settings page is called
<action name="loginAction" class="action.LoginAction"> <result name="" type="dispatcher"></result> </action>
Type attribute can be used in the <result> are individually provided may be provided in a global structs-default.xml in:
<result-types> <result-type name="chain" class="com.opensymphony.xwork2.ActionChainResult"/> <result-type name="dispatcher" class="org.apache.struts2.result.ServletDispatcherResult" default="true"/> <result-type name="freemarker" class="org.apache.struts2.views.freemarker.FreemarkerResult"/> <result-type name="httpheader" class="org.apache.struts2.result.HttpHeaderResult"/> <result-type name="redirect" class="org.apache.struts2.result.ServletRedirectResult"/> <result-type name="redirectAction" class="org.apache.struts2.result.ServletActionRedirectResult"/> <result-type name="stream" class="org.apache.struts2.result.StreamResult"/> <result-type name="velocity" class="org.apache.struts2.result.VelocityResult"/> <result-type name="xslt" class="org.apache.struts2.views.xslt.XSLTResult"/> <result-type name="plainText" class="org.apache.struts2.result.PlainTextResult" /> <result-type name="postback" class="org.apache.struts2.result.PostbackResult" /> </result-types>
The default property is set to true. The default for the dispatcher, forwarding.
Set interceptor
<package name="action" namespace="/action" extends="struts-default"> <interceptors> <interceptor name="" class=""></interceptor> <interceptor-stack name=""> <interceptor-ref name="" /> <interceptor-ref name="" /> </interceptor-stack> </interceptors> <default-interceptor-ref name=""></default-interceptor-ref> <action name="loginAction" class="action.LoginAction" method="exe"> <interceptor-ref name=""></interceptor-ref> <interceptor-ref name=""></interceptor-ref> </action> </package>
Sign interceptor in <interceptors>, the interceptor stack.
<Interceptor> register an interceptor, name specifies the name of the interceptor, class designated java class corresponding to the interceptor.
<Interceptor-stack> register an interceptor stack, name specifies the name of the interceptor stack. <Interceptor-ref /> Specifies the reference to the interceptor.
May be used in the <action> in <interceptor-ref name = ""> </ interceptor-ref> Set the current <action> interceptors to be used, the interceptor stack, a <interceptor-ref name = ""> </ interceptor -ref> reference to an interceptor interceptor stack can use multiple <interceptor-ref name = ""> </ interceptor-ref>.
May also be provided in <default-interceptor-ref name = ""> </ default-interceptor-ref> default interceptor whole package, interceptor stack, this package all the action is valid.
Cited interceptor, the interceptor stack can be your own definition, can also be structs-default.xml comes with.
<Package> child element is a certain sequence, <action> to put last.
Can be modeled structs-default.xml configuration.