Detailed explanation of common configuration of struts2

■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■↓↓↓↓↓↓↓↓↓ Struts2 framework commonly used configuration details↓↓↓ ↓↓↓↓↓↓↓↓■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>




<!-- Introduce the 2.3.dtd constraint file located under the Struts2 framework core package-->

<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">


<!-- Create the root tag defined in the dtd constraints file -->
<struts>

11111111111111111111111111 Constant 11111111111111111111111111111

<!-- ◆Custom Constant Configuration◆ -->

<!-- 
Commonly used constants in the common struts-default constant definition file

struts.i18n.encoding === defines the encoding set, the default is UTF-8, only for post submission
struts.multipart.parser === Parse the uploaded file
struts.multipart.saveDir === directory for cached files
struts.multipart.maxSize === Set the size of the uploaded file, the default is 2M
struts.action.entension === Set the access suffix, the default is action, and spaces 
struts.enable.dynamicMethodinvovation === dynamic method invocation, the default is true,
    When it is running online... it must be closed,
    Because it is not safe.
    Syntax; access path plus ! method name
struts.ui.theme === the main body of the strus page  

◆◆◆◆◆Note; configuration constants are basically used <constant> tags
And the name attribute of this tag is the constant name of the configuration
value is the configured value

write;
<constant name="default.properties constant" value="value"></constant>

-->

<!-- constant; codeset -->
<constant name="struts.i18n.encoding" value="UTF-8"></constant>

<!-- constant; access suffix -->
<constant name="struts.action.extension" value="do,,"></constant>

<!-- constant; dynamic method invocation syntax Add ! method name to the access suffix, it is closed online, not safe -->
<constant name="struts.enable.DynamicMethodInvocation" value="false"></constant>

<!-- Set the cache directory for uploaded files, the default is the cache directory under the server or the temporary file under the system -->
<constant name="struts.multipart.saveDir" value="f:/"></constant>

<!-- Set the maximum upload file size, the default is 2M-->
<constant name="struts.multipart.maxSize" value="2222222222"></constant>


22222222222222222222222222 <package> details 2222222222222222222222222222

<!-- 
Package; is used to distinguish actions of the same name, and easy to manage

name is the unique identifier for this package
extends basically inherits the struts-default package, which defines a large number of elements,
Elements of this package can only be used if they inherit this package

The abdstract abstract package is used for general configuration,
Because if this interceptor is to be used in many actions, the abstract package is used
The abstract package does not have action tags and namespace attributes.
Because it is a general configuration in this configuration file.
-->

<package name="mydefault" extends="struts-default" abstract="true">
<!-- 
interceptors are used to distinguish interceptors with the same name and are easy to manage, similar to the role of packages

-->
<interceptors>
<!-- 
interceptor defines a specific interceptor class

name is a unique identifier for this interceptor configuration
class is the corresponding interceptor path
-->
<interceptor name="inter1" class="com.stuts._02interceptorss._01Intercepator1"></interceptor>
<interceptor name="inter2" class="com.stuts._02interceptorss._02Interceptor2"></interceptor>
<!-- 
interceptor-stack is to use all interceptors together,
Because in the process of development, more than one interceptor may be required to work directly.
name is the name of this interceptor stack

-->
<interceptor-stack name="mystack">
<!-- 
interceptor-ref is to define the interceptors that work in this stack, and the order of execution follows the order here

When a custom interceptor is used, the interceptor provided by Struts2 will be overwritten.
Generally, the interceptor provided by Struts2 will be referenced again, and will be placed first,
Because it is placed in the first place, the custom interceptor can use the data obtained by the parameter interceptor, etc.
-->
<interceptor-ref name="defaultStack"></interceptor-ref>
<interceptor-ref name="inter1"></interceptor-ref>
<interceptor-ref name="inter2"></interceptor-ref>
</interceptor-stack>
</interceptors>
</package>


33333333333333333333333 <package>Basic configuration 333333333333333333333333333333

<!-- 
Create a package to store business processing class methods,
It is also to avoid the duplication of multiple actions and to facilitate management

name is the unique identifier for this package and is not optional
extends inherits the struts-default file under the Struts2 framework,
Only elements of this default file can be used
namesapce is the domain name space for accessing this package, it is optional, the default is / 
-->
<package name="stack" extends="struts-default" namespace="/stack">



------------------------------------------------ View markup Global configuration ------------------------------------------------ ------------------

<!-- 
The <global-result> tag is a process that defines a global business processing method

under <package> only affects all <action> under <package>
-->
<global-results>
<result name="input">/error.jsp</result>
</global-results>


-------------------------------------------------- <action>Configuration --------------------------------------------- ------------------------

<!-- 
action is used to identify the business processing method of a class

name is used to represent this action,
The unique identifier under this package, is not optional,
It is also the namespace that accesses this action.

If there are multiple actions with the same name, use the one defined later

class is the path to the class of this business processing method,
Package name + class name, is optional, the default is ActionSupport

method is the name of this business processing method,
is optional, default is execute()

Another; and there is a wildcard * in the <action> tag when accessing,
It can be added or not added, if it is added, it must be the method name that determines the access

In the method attribute, if you want to refer to this wildcard, use {num} to specify which wildcard to refer to

-->
 
<action name="stack_*" class="com.strurs2.proctice._01ValueStack" method="{1}">


--------------------------------------------------------- <param> Tag parsing ------------------------------------------------ ------------------------
 
 
<!-- 
    <param> This tag is similar to the local variable configuration in the web.xml file
     
    And this is also called action attribute injection,
    And can be modified by this value at any time,
        At that time, the name must be defined with the Action class,
        The member variable name is the same and this member variable,
        A setter method must be provided.
  -->
  
 <param name="test">/xxx</param>
 

--------------------------------------------------------- <result> Tag parsing ------------------------------------------------ ---------------------------------------
 
 
 
<!-- 
   result is to operate according to the result returned by this business processing method

name is the result returned by this business processing method,
is optional, default is SUCCESS

type is the type (method) of this business processing method
is optional, the default is dispatcher (forwarding)

commonly used types;
  stream --- stream
  
  dispatcher --- forwarding
  chain --- Forward to other Action classes
  
  redirect --- redirect
  redirectAction --- redirect to another Action class
  plainText --- write out in plain text


◆Note; you can refer to the core core package under the Struts2 framework
The struts-default.xml file defines the value of the type attribute  

The content is the operation after the result returned by this business processing method
-->
<result>/stack.jsp</result> 

----------------------------------------------------------------------------------------------------------------------------

</action>
</package>
</struts>

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326728606&siteId=291194637