日期:2014-05-20  浏览次数:20860 次

求助,关于spring管理struts2的配置问题
问题描述:
我在网上查找了一些配置的例子,有好多配spring管理struts2的例子当中都没有配置 struts-config.xml文件,我以前也这样配过,但是现在把以前配好的例子拿出来运行,页面跳不过action里,这是为什么,上代码给大家
以下是web.xml配置 
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/applicationContext.xml</param-value>
</context-param>

<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

</web-app>

下边是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>
<constant name="struts.objectFactory.spring.autoWire" value="spring" />
<constant name="struts.objectFactory" value="spring" />
  <constant name="struts.devMode" value="true" />
  <package name="default" extends="struts-default" >
  <!--  
  <interceptors>
  <interceptor name="testInter" class="com.test.interceptor.testInterceptor">
  </interceptor>
  <interceptor-stack name="defaults">
  <interceptor-ref name="defaultStack"></interceptor-ref>
  </interceptor-stack>
 
  </interceptors>  
  -->
  <action name="login" class="dss">
  <result name="SUCCESS" >/success.jsp</result>
  <result name="input">/index.jsp</result>
  <!-- <interceptor-ref name="testInter"></interceptor-ref>
  <interceptor-ref name="defaults"></interceptor-ref>
  -->
  </action>
  </package>
</struts>
下边是 /testStruts2/src/applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans 
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="dss" class="com.test.action.LoginAction" scope="prototype">

</bean>

</beans>

index.jsp文件如下

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();