论坛首页 入门技术论坛

struts+spring+hibernate整合了一天了,还没成功

浏览 16935 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (1) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-08-15  
struts+spring+hibernate整合了一天了,还没成功,请各位看看,哪里不对了

错误提示如下:

HTTP Status 404 - Servlet action is not available

type Status report

message Servlet action is not available

description The requested resource (Servlet action is not available) is not available.
Apache Tomcat/5.5.23


struts-config.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="findUserForm" type="org.xredleaf.form.FindUserForm" />

  </form-beans>

  <global-exceptions />
  <global-forwards />
  <action-mappings >
    <action
      attribute="findUserForm"
      input="/form/findUser.jsp"
      name="findUserForm"
      path="/findUser" 
      scope="request" 
      validate="true"
     
       />

  </action-mappings>
	
  <message-resources parameter="org.xredleaf.ApplicationResources" />
  
  <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
    <set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml" />
  </plug-in>
  
</struts-config> 


applicationContext.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="DataSoure"
		class="org.apache.commons.dbcp.BasicDataSource">
		<property name="driverClassName">
			<value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
		</property>
		<property name="url">
			<value>jdbc:microsoft:sqlserver://localhost:1433</value>
		</property>
		<property name="username">
			<value>sa</value>
		</property>
		<property name="password">
			<value>123456</value>
		</property>
	</bean>
	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="dataSource">
			<ref bean="DataSoure" />
		</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">
					org.hibernate.dialect.SQLServerDialect
				</prop>
			</props>
		</property> 
		<property name="mappingResources">
			<list>
				<value>org/xredleaf/dao/Sysuser.hbm.xml</value>
			</list>
		</property> 
	</bean>
	<bean id="SysuserDAO" class="org.xredleaf.dao.SysuserDAO">
		<property name="sessionFactory">
			<ref bean="sessionFactory" />
		</property>
	</bean>
	
	<bean name="/findUser" class="org.xredleaf.action.FindUserAction" singleton="false">  
	    <property name="dao">
	        <ref bean="SysuserDAO"/>
	    </property>
	</bean>
	
</beans>


SysuserDAO.java内容如下:

package org.xredleaf.dao;

import java.util.Date;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 * Data access object (DAO) for domain model class Sysuser.
 * @see org.xredleaf.dao.Sysuser
 * @author MyEclipse - Hibernate Tools
 */
public class SysuserDAO extends HibernateDaoSupport {

    private static final Log log = LogFactory.getLog(SysuserDAO.class);

	//property constants
	public static final String USERNAME = "username";
	public static final String PASSWORD = "password";
	public static final String TYPE = "type";

	protected void initDao() {
		//do nothing
	}
    
	public void SysuserDAO(){
		log.debug("init SysuserDAO");
	}
    public void save(Sysuser transientInstance) {
        log.debug("saving Sysuser instance");
        try {
            getHibernateTemplate().save(transientInstance);
            log.debug("save successful");
        } catch (RuntimeException re) {
            log.error("save failed", re);
            throw re;
        }
    }
    
	public void delete(Sysuser persistentInstance) {
        log.debug("deleting Sysuser instance");
        try {
            getHibernateTemplate().delete(persistentInstance);
            log.debug("delete successful");
        } catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }
    
    public Sysuser findById( java.lang.Integer id) {
        log.debug("getting Sysuser instance with id: " + id);
        try {
            Sysuser instance = (Sysuser) getHibernateTemplate()
                    .get("org.xredleaf.pojo.Sysuser", id);
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }
    
    
    public List findByExample(Sysuser instance) {
        log.debug("finding Sysuser instance by example");
        try {
            List results = getHibernateTemplate().findByExample(instance);
            log.debug("find by example successful, result size: " + results.size());
            return results;
        } catch (RuntimeException re) {
            log.error("find by example failed", re);
            throw re;
        }
    }    
    
    public List findByProperty(String propertyName, Object value) {
      log.debug("finding Sysuser instance with property: " + propertyName
            + ", value: " + value);
      try {
         String queryString = "from Sysuser as model where model." 
         						+ propertyName + "= ?";
		 return getHibernateTemplate().find(queryString, value);
      } catch (RuntimeException re) {
         log.error("find by property name failed", re);
         throw re;
      }
	}

	public List findByUsername(Object username) {
		return findByProperty(USERNAME, username);
	}
	
	public List findByPassword(Object password) {
		return findByProperty(PASSWORD, password);
	}
	
	public List findByType(Object type) {
		return findByProperty(TYPE, type);
	}
	
    public Sysuser merge(Sysuser detachedInstance) {
        log.debug("merging Sysuser instance");
        try {
            Sysuser result = (Sysuser) getHibernateTemplate()
                    .merge(detachedInstance);
            log.debug("merge successful");
            return result;
        } catch (RuntimeException re) {
            log.error("merge failed", re);
            throw re;
        }
    }

    public void attachDirty(Sysuser instance) {
        log.debug("attaching dirty Sysuser instance");
        try {
            getHibernateTemplate().saveOrUpdate(instance);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
    
    public void attachClean(Sysuser instance) {
        log.debug("attaching clean Sysuser instance");
        try {
            getHibernateTemplate().lock(instance, LockMode.NONE);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }

	public static SysuserDAO getFromApplicationContext(ApplicationContext ctx) {
    	return (SysuserDAO) ctx.getBean("SysuserDAO");
	}
}


FindUserAction.java内容如下:

/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package org.xredleaf.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.xredleaf.dao.Sysuser;
import org.xredleaf.dao.SysuserDAO;
import org.xredleaf.form.FindUserForm;

/** 
 * MyEclipse Struts
 * Creation date: 08-15-2007
 * 
 * XDoclet definition:
 * @struts.action path="/findUser" name="findUserForm" input="/form/findUser.jsp" scope="request" validate="true"
 */
public class FindUserAction extends Action {
	
	private static final Log log = LogFactory.getLog(FindUserAction.class);
	private SysuserDAO dao;
	 
	public FindUserAction(){
		log.debug("init FindUserAction");
	} 
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		log.debug("start...");
		FindUserForm findUserForm = (FindUserForm) form;
		
		List list = dao.getHibernateTemplate().loadAll(Sysuser.class);
		//dao=(SysuserDAO)getBean("SysuserDAO");

		log.debug(list.size()); 
		return null;
	}
	
	public void setDao(SysuserDAO dao){
		this.dao=dao;
	}
	
	public SysuserDAO getDao(){
		return dao;
	}
	
	
	
}



web.xml配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
      <param-name>config</param-name>
      <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <init-param>
      <param-name>debug</param-name>
      <param-value>3</param-value>
    </init-param>
    <init-param>
      <param-name>detail</param-name>
      <param-value>3</param-value>
    </init-param>
    <load-on-startup>0</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>
</web-app>
   发表时间:2007-08-15  
action 都没找到,这是哪里配置错了???
0 请登录后投票
   发表时间:2007-08-15  
对Struts 1.x不熟悉,不过有个疑问:

     <bean name="/findUser" class="org.xredleaf.action.FindUserAction" singleton="false">    
         <property name="dao">  
             <ref bean="SysuserDAO"/>  
         </property>  
     </bean>


为什么这个bean的名字里有个/号?
0 请登录后投票
   发表时间:2007-08-15  
movingboy 写道
对Struts 1.x不熟悉,不过有个疑问:

     <bean name="/findUser" class="org.xredleaf.action.FindUserAction" singleton="false">    
         <property name="dao">  
             <ref bean="SysuserDAO"/>  
         </property>  
     </bean>


为什么这个bean的名字里有个/号?


对应struts-config.xml文件里action path = "/findUser"的名字
0 请登录后投票
   发表时间:2007-08-15  
兄弟姐妹们帮忙找找原因啊,做过的肯定知道的呀!!!
0 请登录后投票
   发表时间:2007-08-16  
找个视频重做一遍
1 请登录后投票
   发表时间:2007-08-16  
步骤都和书上一样的,昨天晚上重做了两遍,只是没把hibernate加上,结果就可以了,步骤是一模一样的,不知道问题出在哪里
0 请登录后投票
   发表时间:2007-08-16  
我感觉好象是struts和spring集成出问题了
0 请登录后投票
   发表时间:2007-08-17  
  <action-mappings > 
    <action 
      attribute="findUserForm" 
      input="/form/findUser.jsp" 
      name="findUserForm" 
      path="/findUser"   
      scope="request"   
      validate="true" 
        type="org.springframework.web.struts.DelegatingActionProxy"

       /> 
 
  </action-mappings> 
0 请登录后投票
   发表时间:2007-08-17  
感觉还是先把struts能用上再去管下面的吧 404啊,找不到啊
0 请登录后投票
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics