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>
現在檔案夾結構看起來如下: