其他可能相关的配置和实现类如下:
<?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>
  <form-beans >
    <form-bean name="loginForm" type="ssh.struts.form.LoginForm" />
  </form-beans>
  <action-mappings >
    <action
      attribute="loginForm"
      input="/login.jsp"
      name="loginForm"
      path="/login"
      scope="request"
      type="org.springframework.web.struts.DelegatingActionProxy">
      <forward name="suc" path="/success.jsp"></forward>
      <forward name="fal" path="/login.jsp"></forward>
      </action>
  </action-mappings>
  <message-resources parameter="ssh.struts.ApplicationResources" />
    <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
    <set-property property="contextConfigLocation"
                  value="/WEB-INF/applicationContext.xml" />
    </plug-in>
</struts-config>
======================================================================
Action 类
package ssh.struts.action;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import ssh.dao.impl.StudentDaoImpl;
import ssh.struts.form.LoginForm;
public class LoginAction extends Action {
private StudentDaoImpl studentDaoImpl;
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
LoginForm loginForm = (LoginForm) form;// TODO Auto-generated method stub
  String name=loginForm.getUsername();
  String pwd=loginForm.getPassword();
  String forward=null;
  List list=studentDaoImpl.getStuByName(name);
  if(list!=null){
  if(pwd.equals("123")){
        forward="suc";
  }else{
  ActionErrors errors=new ActionErrors();
  errors.add("loginerror", new ActionMessage("error.login"));
  forward="fal";
  }
  }
  return mapping.findForward(forward);
}
public void setStudentDaoImpl(StudentDaoImpl studentDaoImpl) {
this.studentDaoImpl = studentDaoImpl;
}
}
=====================================================
DAO实现类
package ssh.dao.impl;
import java.util.List;
import org.hibernate.SessionFactory;
import ssh.dao.i.StudentDAO;
public class StudentDaoImpl implements StudentDAO {
private SessionFactory sessionFactory;
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
public List getStuByName(String name) { return this.sessionFactory.getCurrentSession().createQuery(
"from StudentInfo s where s.username=?").setParameter(0, name)
.list();
}}各位高手帮小弟看看不胜感激!!谢谢

解决方案 »

  1.   

    <property name="mappingResources"> 
    <list> 
    <value>ssh/model/StudentInfo.hbm.xml </value> </list> 
    </property> 
    这里有错:
    <property name="mappingResources"> 
    <list> 
    <value>StudentInfo.hbm.xml </value> </list> 
    </property> 你改下这里试试 我看了下你的代码,其他地方好像都没错
      

  2.   

    DAO层中为什么不使用Spring提供的HibernateDaoSupport类?
      

  3.   

    我按照你的方法该了 但是多了错误说StudentInfo.hbm.xml 路径不对
    应该加包名ssh/model吧?
      

  4.   

    StudentInfo.hbm.xml 是否和class文件放在一起的 ?
      

  5.   

    <bean id="transactionInterceptor" 
          class="org.springframework.transaction.interceptor.TransactionInterceptor"> 
          <property name="transactionManager" ref="transactionManager">
          </property>
          <property name="target">
          .....
          </property>

          <property name="transactionAttributes"> 
          <props> 
              <prop key="get*">PROPAGATION_REQUIRED </prop> 
          </props> 
    </property> 
      

  6.   

    我觉得使用org.springframework.orm.hibernate3.LocalSessionFactoryBean来定义sessionFactory的话,DAO 实现类里面要继承HibernateDaoSupport这样就没问题了.
    因为这里的Hibernate是由spring管理的。