struts2導入多個xml引入報錯


struts.xml

Xml代碼   收藏代碼
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!-- 指定Struts 2配置文件的DTD信息 -->  
  3. <!DOCTYPE struts PUBLIC  
  4.     "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"  
  5.     "http://struts.apache.org/dtds/struts-2.3.dtd">  
  6. <!-- Struts 2配置文件的根元素 -->  
  7. <struts>  
  8.     <!-- struts2 默認配置文件,必須加進來 有這里看出,當前文件的路徑是跟路徑下classes路徑,所以其他的文件要從classes這個路徑開始找 -->  
  9.     <include file="struts-plugin.xml" />  
  10.     <include file="struts-default.xml" />  
  11.     <!-- 自己添加的配置文件 -->  
  12.     <include file="../struts2/struts_user.xml" />  
  13.     <include file="../struts2/struts_sign.xml" />  
  14. </struts>  



struts_user.xml

Xml代碼   收藏代碼
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!-- 指定Struts 2配置文件的DTD信息 -->  
  3. <!DOCTYPE struts PUBLIC  
  4.     "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"  
  5.     "http://struts.apache.org/dtds/struts-2.3.dtd">  
  6. <!-- Struts 2配置文件的根元素 -->  
  7. <struts>  
  8.     <!-- 配置了系列常量 -->  
  9.     <constant name="struts.i18n.encoding" value="UTF-8" />  
  10.     <constant name="struts.devMode" value="true" />  
  11.   
  12.     <package name="Aberic" extends="struts-default">  
  13.         <!-- 定義處理用戶請求的Action -->  
  14.         <action name="login" class="loginAction">  
  15.             <!-- 為兩個邏輯視圖配置視圖頁面 -->  
  16.             <result name="error">/error.jsp</result>  
  17.             <result name="success">/admin/admin.jsp</result>  
  18.             <interceptor-ref name="sessionstack" />  
  19.         </action>  
  20.     </package>  
  21. </struts>  



struts_sign.xml

Xml代碼   收藏代碼
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!-- 指定Struts 2配置文件的DTD信息 -->  
  3. <!DOCTYPE struts PUBLIC  
  4.     "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"  
  5.     "http://struts.apache.org/dtds/struts-2.3.dtd">  
  6. <!-- Struts 2配置文件的根元素 -->  
  7. <struts>  
  8.     <!-- 配置了系列常量 -->  
  9.     <constant name="struts.i18n.encoding" value="UTF-8" />  
  10.     <constant name="struts.devMode" value="true" />  
  11.   
  12.     <package name="Aberic" extends="struts-default">  
  13.         <!-- 定義處理用戶請求的Action -->  
  14.         <action name="sign" class="PhoneSignAction">  
  15.             <!-- 因為僅提供手機簽到,故不配置任何視圖 -->  
  16.             <result type="stream">  
  17.                 <param name="contentType">text/html</param>  
  18.                 <param name="inputName">inputStream</param>  
  19.             </result>  
  20.         </action>  
  21.     </package>  
  22. </struts>  



web.xml

Xml代碼   收藏代碼
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">  
  3.   <servlet>  
  4.     <servlet-name>proxoolServletConfigurator</servlet-name>  
  5.     <servlet-class>  
  6.            org.logicalcobwebs.proxool.configuration.ServletConfigurator  
  7.         </servlet-class>  
  8.     <init-param>  
  9.       <param-name>xmlFile</param-name>  
  10.       <param-value>WEB-INF/proxool.xml</param-value>  
  11.     </init-param>  
  12.     <load-on-startup>1</load-on-startup>  
  13.   </servlet>  
  14.   <context-param>  
  15.     <param-name>log4jConfigLocation</param-name>  
  16.     <param-value>/WEB-INF/log4j.properties</param-value>  
  17.   </context-param>  
  18.   <context-param>  
  19.     <param-name>log4jRefreshInterval</param-name>  
  20.     <param-value>60000</param-value>  
  21.   </context-param>  
  22.   <listener>  
  23.     <listener-class>    
  24.             org.springframework.web.util.Log4jConfigListener    
  25.         </listener-class>  
  26.   </listener>  
  27.   <context-param>  
  28.     <param-name>contextConfigLocation</param-name>  
  29.     <param-value>/WEB-INF/spring/applicationContext.xml</param-value>  
  30.   </context-param>  
  31.   <listener>  
  32.     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
  33.   </listener>  
  34.   <filter>  
  35.     <filter-name>struts2</filter-name>  
  36.     <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>  
  37.     <init-param>  
  38.       <param-name>config</param-name>  
  39.       <param-value>struts-default.xml,struts-plugin.xml,../struts2/struts.xml</param-value>  
  40.     </init-param>  
  41.   </filter>  
  42.   <filter-mapping>  
  43.     <filter-name>struts2</filter-name>  
  44.     <url-pattern>/*</url-pattern>  
  45.   </filter-mapping>  
  46.   <session-config>  
  47.     <session-timeout>30</session-timeout>  
  48.   </session-config>  
  49.   <welcome-file-list>  
  50.     <welcome-file>index.jsp</welcome-file>  
  51.   </welcome-file-list>  
  52. </web-app>  



因為我配的有spring,所以action中class沒有指定類而是交給spring管理了
現在有一個奇怪的問題就是當我把../struts2/struts_user.xml先include進去的時候,就能夠成功加載進去,登陸操作無誤
當我把../struts2/struts_sign.xml放在../struts2/struts_user.xml上面的時候,就成了簽到成功,但登陸卻提示找不到action了
總之就是只能有一個生效,這個問題糾結了好幾天了

 

 

采納的答案

題主好。

看了一下配置文件,發現兩個配置文件的packageName都是相同的,建議修改成不同的名稱試試


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM