struts.xml
<?xml version="1.0" encoding="utf-8" ?> <!doctype struts public "-//apache software foundation//dtd struts configuration 2.0//en" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="default" namespace="/" extends="struts-default"> </package> <package name="audit" namespace="/audit" extends="struts-default"> <action name="welcomeaudit"> <result>pages/welcome_audit.jsp</result> </action> </package> <package name="user" namespace="/user" extends="struts-default"> <action name="welcomeuser"> <result>pages/welcome_user.jsp</result> </action> </package> </struts>
在上面的struts配置文件中,组织所有“用户”和“审核”配置设置在一个文件中,这不是建议的,必须回避。应该打破这种形式,而将struts.xml文件分成更小的模块相关的部分。
struts-audit.xml
<?xml version="1.0" encoding="utf-8" ?> <!doctype struts public "-//apache software foundation//dtd struts configuration 2.0//en" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="audit" namespace="/audit" extends="struts-default"> <action name="welcomeaudit"> <result>pages/welcome_audit.jsp</result> </action> </package> </struts>
struts-user.xml
<?xml version="1.0" encoding="utf-8" ?> <!doctype struts public "-//apache software foundation//dtd struts configuration 2.0//en" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="user" namespace="/user" extends="struts-default"> <action name="welcomeuser"> <result>pages/welcome_user.jsp</result> </action> </package> </struts>
struts.xml
<?xml version="1.0" encoding="utf-8" ?> <!doctype struts public "-//apache software foundation//dtd struts configuration 2.0//en" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="default" namespace="/" extends="struts-default"> </package> <include file="conf/user-struts.xml"></include> <include file="conf/audit-struts.xml"></include> </struts>
现在文件夹结构看起来如下: