问题描述:
我在网上查找了一些配置的例子,有好多配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();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'success.jsp' starting page</title>
    
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->  </head>
  
  <body>
   <s:form action="login.action" method="post"  theme="simple"> 
suserId<s:textfield  name="user.userId"></s:textfield>
passward<s:textfield  name="user.passWard"></s:textfield>
<s:submit value="submit"></s:submit>
</s:form> 

  </body>
</html>action里边什么都没有,只有一个试验跳转的语句
package com.test.action;import com.opensymphony.xwork2.ActionSupport;
import com.test.models.User;public class LoginAction   extends ActionSupport{ private User user;
public String login(){
//System.out.println(user.getPassWard());
System.out.println("使用action");
return "SUCCESS";

}
public String add(){
return "add";

}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public void loginValidate(){

}
@Override
public void validate() {
this.addFieldError("user.userId", "useriderrpo");
}
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
//return super.execute();
//System.out.println(user.getPassWard());
System.out.println("使用的是excute的action");
return "SUCCESS";
}
}
请各位帮我看一下,为什么我的配置不能跳转进action里边

解决方案 »

  1.   

    没有抛出任何异常,就是跳转不进action内
      

  2.   

    struts提供的针对spring的插件包copy到lib目录去
      

  3.   

    我把那些相关的jar包全部又查找了一次,可还是跳转不进去,如果有高手的话,可以联系我QQ,或者留下一个信箱,我把我的项目打包给发过去,请帮我查看一下,很小的项目,初学,请大家多多帮忙
    QQ36679697,或者是在回复中留下信箱,我给打包发过去
      

  4.   

    己成功调出,原因在于spring下的配置文件中没有实例化action里边的一个bean,我把那个bean全部注消掉后系统正常中转至action,在spring配置文件spplicationcontext.xml中加载正确的bean信息即可