struts.xml的路径

web.xml中welcome-file的类型不能为action,但是可以是servlet,也可以在页面中添加

<meta http-equiv="refresh" content="0; url=index.action">

跳转。

 

struts.xml的默认位置在src下面,如果想改变struts.xml的位置的话,比如放在WEB-INF/config文件夹下面,则需要在web.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,../config/struts.xml</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>struts2</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

 

struts-default.xml,struts-plugin.xml是必需的,

默认编译后的类文件放在WEB-INF/classes文件夹内(即使编译路径为工程目录下面的build/classes),所以struts.xml前面的../表示classes文件夹的上一层路径,即WEB-INF文件夹路径。

 

如果struts.xml放在src下面的包下面,如在包cn.sh下面,则改为cn/sh/struts.xml即可。

 

猜你喜欢

转载自616873603-qq-com.iteye.com/blog/1836212