SSH框架中所有action为何都被执行了两次,配置如下

web.xml

 <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>SMU</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</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>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
  </context-param>
</web-app>

struts.xml

 <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="default" extends="struts-default">
<action name="browseAllStations" class="stationAction" method="browseAllStations">
<result name="success">/menu.jsp</result>
</action>

<action name="browseAllRequirements" class="requirementAction" method="browseAllRequirements">
<result name="success">/main.jsp</result>
<interceptor-ref name="defaultStack"></interceptor-ref>
</action>
<action name="addScore" class="scoreAction" method="addScore">
<result name="success">/addScore_success.jsp</result>
<result name="error">/addScore.jsp</result>
<interceptor-ref name="defaultStack"></interceptor-ref>
</action>
</package>
</struts>    

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"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd" xmlns:tx="http://www.springframework.org/schema/tx">


    <bean id="dataSource"
        class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
        <property name="url"
            value="jdbc:mysql://localhost:3306/SMU?useUnicode=true&amp;characterEncoding=utf-8">
        </property>
        <property name="username" value="root"></property>
        <property name="password" value="123456"></property>
    </bean>
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource">
            <ref bean="dataSource" />
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">
                    org.hibernate.dialect.MySQLDialect
                </prop>
            </props>
        </property>
        <property name="mappingResources">
            <list>
                <value>com/smu/model/Teacher.hbm.xml</value>
                <value>com/smu/model/Station.hbm.xml</value>
                <value>com/smu/model/Requirement.hbm.xml</value>
                <value>com/smu/model/Case.hbm.xml</value>
                <value>com/smu/model/Student.hbm.xml</value>
                <value>com/smu/model/Score.hbm.xml</value>
                <value>com/smu/model/System.hbm.xml</value></list>
        </property></bean>
        <bean id="stationDAO" class="com.smu.dao.impl.StationDAO">
        <property name="sessionFactory">
        <ref bean="sessionFactory"></ref>
        </property>
        </bean>
        <bean id="stationService" class="com.smu.service.impl.StationService">
        <property name="stationDAO" ref="stationDAO"></property>
        </bean>
        <bean id = "stationAction" class="com.smu.action.StationAction">
        <property name="stationService" ref="stationService"></property>
        </bean>

            <bean id="requirementDAO" class="com.smu.dao.impl.RequirementDAO">
        <property name="sessionFactory">
        <ref bean="sessionFactory"></ref>
        </property>
        </bean>
        <bean id="requirementService" class="com.smu.service.impl.RequirementService">
        <property name="requirementDAO" ref="requirementDAO"></property>
        </bean>
        <bean id = "requirementAction" class="com.smu.action.RequirementAction">
        <property name="requirementService" ref="requirementService"></property>

        </bean>


        <bean id="scoreDAO" class="com.smu.dao.impl.ScoreDAO">
        <property name="sessionFactory">
        <ref bean="sessionFactory"></ref>
        </property>
        </bean>
        <bean id="scoreService" class="com.smu.service.impl.ScoreService">
        <property name="scoreDAO" ref="scoreDAO"></property>
        </bean>
        <bean id = "scoreAction" class="com.smu.action.ScoreAction">
        <property name="scoreService" ref="scoreService"></property>

        </bean>
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
    <tx:annotation-driven transaction-manager="transactionManager" /></beans>

2个回答

从配置看不出问题...
你既然能启动配置应该没有问题的.
不行的话你设置断点, 看一下调用栈, 2次是不是一样都是从哪里进去的.

看一下你的js之类的,是不是在封装请求时,请求了两次action。

TSAPR
black-rat 回复空想神话:最好把所有的代码贴出来,光看是看不出来的
4 年多之前 回复
qq_25453303
空想神话 回复TSAPR: Jsp页面里没有写任何js![图片说明](http://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/001/face/9.gif)
4 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐