struts2配置文件放在resource包里如何生效
时间: 2023-12-21 15:04:44 浏览: 110
如果您想将Struts2配置文件放在resource包中,可以按照以下步骤进行配置:
1. 在src/main/resources目录下创建struts.xml文件。
2. 在web.xml中配置Struts2的过滤器Filter:
```
<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>
```
3. 在struts.xml中配置Struts2的Action和Result:
```
<struts>
<package name="default" extends="struts-default">
<action name="hello" class="com.example.HelloAction">
<result>/hello.jsp</result>
</action>
</package>
</struts>
```
4. 在项目运行时,Struts2会自动加载src/main/resources目录下的struts.xml文件。
注意:如果您使用的是Maven项目,需要将资源文件夹标记为资源目录。在pom.xml文件中添加以下配置:
```
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
```
阅读全文
相关推荐














