struts.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <!-- 指定Struts 2配置文件的DTD信息 -->
- <!DOCTYPE struts PUBLIC
- "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
- "http://struts.apache.org/dtds/struts-2.3.dtd">
- <!-- Struts 2配置文件的根元素 -->
- <struts>
- <!-- struts2 默認配置文件,必須加進來 有這里看出,當前文件的路徑是跟路徑下classes路徑,所以其他的文件要從classes這個路徑開始找 -->
- <include file="struts-plugin.xml" />
- <include file="struts-default.xml" />
- <!-- 自己添加的配置文件 -->
- <include file="../struts2/struts_user.xml" />
- <include file="../struts2/struts_sign.xml" />
- </struts>
struts_user.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <!-- 指定Struts 2配置文件的DTD信息 -->
- <!DOCTYPE struts PUBLIC
- "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
- "http://struts.apache.org/dtds/struts-2.3.dtd">
- <!-- Struts 2配置文件的根元素 -->
- <struts>
- <!-- 配置了系列常量 -->
- <constant name="struts.i18n.encoding" value="UTF-8" />
- <constant name="struts.devMode" value="true" />
- <package name="Aberic" extends="struts-default">
- <!-- 定義處理用戶請求的Action -->
- <action name="login" class="loginAction">
- <!-- 為兩個邏輯視圖配置視圖頁面 -->
- <result name="error">/error.jsp</result>
- <result name="success">/admin/admin.jsp</result>
- <interceptor-ref name="sessionstack" />
- </action>
- </package>
- </struts>
struts_sign.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <!-- 指定Struts 2配置文件的DTD信息 -->
- <!DOCTYPE struts PUBLIC
- "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
- "http://struts.apache.org/dtds/struts-2.3.dtd">
- <!-- Struts 2配置文件的根元素 -->
- <struts>
- <!-- 配置了系列常量 -->
- <constant name="struts.i18n.encoding" value="UTF-8" />
- <constant name="struts.devMode" value="true" />
- <package name="Aberic" extends="struts-default">
- <!-- 定義處理用戶請求的Action -->
- <action name="sign" class="PhoneSignAction">
- <!-- 因為僅提供手機簽到,故不配置任何視圖 -->
- <result type="stream">
- <param name="contentType">text/html</param>
- <param name="inputName">inputStream</param>
- </result>
- </action>
- </package>
- </struts>
web.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <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">
- <servlet>
- <servlet-name>proxoolServletConfigurator</servlet-name>
- <servlet-class>
- org.logicalcobwebs.proxool.configuration.ServletConfigurator
- </servlet-class>
- <init-param>
- <param-name>xmlFile</param-name>
- <param-value>WEB-INF/proxool.xml</param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <context-param>
- <param-name>log4jConfigLocation</param-name>
- <param-value>/WEB-INF/log4j.properties</param-value>
- </context-param>
- <context-param>
- <param-name>log4jRefreshInterval</param-name>
- <param-value>60000</param-value>
- </context-param>
- <listener>
- <listener-class>
- org.springframework.web.util.Log4jConfigListener
- </listener-class>
- </listener>
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>/WEB-INF/spring/applicationContext.xml</param-value>
- </context-param>
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
- </listener>
- <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,../struts2/struts.xml</param-value>
- </init-param>
- </filter>
- <filter-mapping>
- <filter-name>struts2</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- <session-config>
- <session-timeout>30</session-timeout>
- </session-config>
- <welcome-file-list>
- <welcome-file>index.jsp</welcome-file>
- </welcome-file-list>
- </web-app>
因為我配的有spring,所以action中class沒有指定類而是交給spring管理了
現在有一個奇怪的問題就是當我把../struts2/struts_user.xml先include進去的時候,就能夠成功加載進去,登陸操作無誤
當我把../struts2/struts_sign.xml放在../struts2/struts_user.xml上面的時候,就成了簽到成功,但登陸卻提示找不到action了
總之就是只能有一個生效,這個問題糾結了好幾天了
采納的答案
題主好。
看了一下配置文件,發現兩個配置文件的packageName都是相同的,建議修改成不同的名稱試試

