把Struts的action交给Spring管理,在Struts的XML配置好了,<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"><struts-config>
  <data-sources />
  <form-beans >
    <form-bean name="userForm" type="com.struts.form.UserForm" />  </form-beans>  <global-exceptions />
  <global-forwards />
  <action-mappings >
    <action
      attribute="userForm"
      input="/log.jsp"
      name="userForm"
      path="/log"
      scope="request"
      type="org.springframework.web.struts.DelegatingActionProxy" >
      <forward name="ok" path="/logOk.jsp" />
    </action>
    <action
      attribute="userForm"
      name="userForm"
      path="/user"
      scope="request"
      type="org.springframework.web.struts.DelegatingActionProxy" />
  </action-mappings>  <message-resources parameter="com.struts.ApplicationResources" />
    <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
    <set-property property="contextConfigLocation" value="/WEB-INF/classes/applicationContext.xml" />
  </plug-in>  
</struts-config>Srping的applicationContext.xml也指定了action的Bean和与之对应的DAO了。
[code=XML]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"><beans>
<bean id="dbConn" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>net.sourceforge.jtds.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:jtds:sqlserver://127.0.0.1:1433</value>
</property>
<property name="username">
<value>sa</value>
</property>
<property name="password">
<value>123</value>
</property>
</bean>
<bean id="SessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dbConn" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/vo/Userinfo.hbm.xml</value>
<value>com/vo/Userstatus.hbm.xml</value>
</list>
</property>
</bean>
<bean id="UserinfoDAO" class="com.vo.UserinfoDAO">
<property name="sessionFactory">
<ref bean="SessionFactory" />
</property>
</bean>
<bean id="UserstatusDAO" class="com.vo.UserstatusDAO">
<property name="sessionFactory">
<ref bean="SessionFactory" />
</property>
</bean>
<bean name="/log" class="com.struts.action.LogAction">
<property name="userinfoDao">
<ref bean="UserinfoDAO" />
</property>
</bean>
<bean name="/user" class="com.struts.action.UserAction">
<property name="userinfoDao">
<ref bean="UserinfoDAO" />
</property>
</bean>
</beans>可是页面一调用action就报404 Servlet action is not available,求解.[/code]

解决方案 »

  1.   

    确认下你log.jsp里的<form action="log.do">,是不是这样写的!
      

  2.   

    ActionServlet在配置文件Struts-config.xml中没有找到处理请求的Action,象楼上说的那样,看看url是否正确
      

  3.   

     <bean name="/log" class="com.struts.action.LogAction">
            <constructor-arg index="0" ref="UserinfoDAO" />   
     </bean>
    在你对应的LogAction里  写个构造方法 
    UserinfoDAO udao (接口类)public LogAction(UserinfoDAO udao) {
    super();
    this.udao= udao;
    }
      

  4.   

     <bean id="UserinfoDAO" class="com.vo.UserinfoDAO">
            <property name="sessionFactory">
                <ref bean="SessionFactory" />
            </property>
        </bean>com.vo.UserinfoDAO 是接口 还是实现接口的方法  这里应该放实现接口的方法 UserinfoDAOimpl
      

  5.   

    确认下你log.jsp里的 <form action="log.do">,是不是这样写的!别加反斜线!你误解我的意思了!
      

  6.   

    还是不行的话,把你的web.xml贴出来让我看看!