Struts2 learning - custom Struts configuration file path

       The core configuration file of the struts2 framework is the struts.xml file by default, which is usually placed under the WEB-INF/classes directory in the webapp. If Eclipse or MyEclispe is used, it is usually placed in the src root directory of the web project.

1. The default path of the configuration file, configured in web.xml

 Use the following configuration before earlier versions

 

<filter>
        <filter-name>struts2</filter-name>
        <filter-class>
           org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
        </filter-class>
    </filter>
 
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

 

After version 2.3, the following configuration is adopted

 

  <filter>
       <filter-name>struts2</filter-name>
        <filter-class>
           org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
        </filter-class>
    </filter>
 
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

 

 

 2. The configuration in the configuration file custom path web is as follows

      The path to struts.xml in this example is WEB-INF/classes/conf/struts/struts.xml

 

<filter>
		<filter-name>struts2</filter-name>
		<filter-class>
                 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
                </filter-class>
		<init-param>  
            <param-name>config</param-name>  
            <param-value>  
               struts-default.xml,struts-plugin.xml,conf/struts/struts.xml
            </param-value>  
        </init-param>
	</filter>

	<filter-mapping>
	    <filter-name>struts2</filter-name>
	    <url-pattern>/*</url-pattern>
	</filter-mapping>
	

 

 

   Additional Notes*:

  (1) The value of the parameter config consists of three configuration files, and the struts.xml file should be placed at the end of the three configuration files;

  (2) The way struts loads configuration files, struts is not the path of the obtained configuration file relative to the application (project), but relative to src, and for the web, it is the path relative to the /WEB-INF/classes folder;

  (3) Using classpath*:conf/struts/struts/struts.xml in the new version, the path of the configuration file still cannot be found, (refer to other blogs, it seems that the old version can be written in this way)

   The previous version was written as follows

 

<filter>
        <filter-name>struts2</filter-name>
        <filter-class>
          org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
        </filter-class>
        <init-param>
            <param-name>filterConfig</param-name>
            <param-value>classpath:conf/struts/struts.xml</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

 

 Both parameter values ​​and parameter names have changed.

   

 

 

 

Guess you like

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