Where to put struts.xml

后端 未结 6 1826
死守一世寂寞
死守一世寂寞 2021-02-07 04:41

With Struts2 we have to have struts.xml in the class path, so it no longer works to have it under WEB-INF. So the way I got my project to deploy was to stick it und

相关标签:
6条回答
  • 2021-02-07 04:56

    With Struts 1.2, it was required to put the struts-config.xml in the classpath (under WEB-INF folder) but with Struts 2.0, it is required to be in src/main/resources folder.

    See the documentation Struts 2 Documentation here

    I pasted struts.xml in this directory and the project executed fine.

    0 讨论(0)
  • 2021-02-07 05:07

    You can either just put the struts.xml at the root of your source directory or set up an additional resources source directory and put it there. Eclipse quite happily copies it to WEB-INF/classes for you when it does a compilation.

    0 讨论(0)
  • 2021-02-07 05:10

    You can place struts.xml file in src(Java Resources) packages. When the compilation process struts.xml file will generate inside the ROOT/WEB-INF/classes directory.

    if you get the same error again and again better check the struts actions. check the deployed path of the application and you can find out what you want. (struts.xml file)

    0 讨论(0)
  • 2021-02-07 05:11

    I am not using Eclipse so this answer is not specific to your requirements but, I use Maven so we have all the "resources" that are needed by the application in a seperate folder called "resources" and When the application is built these files are copied into the appropriate places automatically. In Netbeans the files in the folder are available and I know that there are persons using eclipse with a similar setup.

    I should point out that our project started from appfuse so most of these configurations were pre made. You can look at how it was done there.

    0 讨论(0)
  • 2021-02-07 05:13

    I am late to the party, we can configure the struts.xml in any directory in the classpath of the web application, but provide the location using the "config" init parameter of the filter configuration in web.xml as below, if my struts.xml file is in "/com/resources/" directory.

       <filter>
            <filter-name>action</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,/com/resources/struts.xml</param-value>
             </init-param>
        </filter>
    

    If we don't provide a config init parameter struts2 by default takes 3 values "struts-default.xml,struts-plugin.xml,struts.xml", you can see the struts2 Dispatcher class code below which will configure these 3 files to the configuration manager.

    String configPaths = (String)this.initParams.get("config");
    if (configPaths == null) {
      configPaths = "struts-default.xml,struts-plugin.xml,struts.xml";
    }
    String[] files = configPaths.split("\\s*[,]\\s*");
    for (String file : files)
      if (file.endsWith(".xml")) {
        if ("xwork.xml".equals(file))
          this.configurationManager.addContainerProvider(createXmlConfigurationProvider(file, false));
        else
          this.configurationManager.addContainerProvider(createStrutsXmlConfigurationProvider(file, false, this.servletContext));
      }
    
    0 讨论(0)
  • 2021-02-07 05:16

    In struts 2 projects, struts.xml file is added in src(Java Resources) folder along with the packages and libraries.

    Please refer the image given below.

    Struts 2 project directory view in eclipse

    If u want to know more about struts 2 project structure please visit this link

    Note: In eclipse, you are not allowed to paste a file directly in src folder. So you need to first paste it in any other place in the project( for example, in 'WebContent' folder), then use move functionality to put it in right place( That is 'src' folder).

    0 讨论(0)
提交回复
热议问题