日期:2014-05-17  浏览次数:20796 次

S2SH整合出现空指针异常,求解!!!
public class loginDao extends HibernateDaoSupport implements IloginDao{

public List login(user user) {
try{String hql="from java_test where name='"+user.getUserName()+"' and pwd='"+user.getPassWord()+"'";
System.out.print("------"+hql);
List list =this.getHibernateTemplate().find(hql);
if(list.size()>0){
System.out.println(list);
return list;
}else return null;
}catch (Exception e){
e.printStackTrace();
return null;
}
}
}



public class LoginService implements ILoginService{
private IloginDao loginDao;

public IloginDao getLoginDao() {
return loginDao;
}
public void setLoginDao(IloginDao loginDao) {
this.loginDao = loginDao;
}

public List login(user user) {
  return this.getLoginDao().login(user);
}
}




public class LoginAction {
private ILoginService loginservice;
private user user;
public ILoginService getLoginservice() {
return loginservice;
}
public void setLoginservice(ILoginService loginservice) {
this.loginservice = loginservice;
}

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


public String execute() throws Exception { 
user.setUserName(user.getUserName());
System.out.println(user.getUserName());
user.setPassWord(user.getPassWord());
System.out.println(user.getPassWord());
List list=loginservice.login(user);

if (list!=null&&list.size()>0) { 
System.out.println("登陆成功"); 
  ServletActionContext.getRequest().setAttribute("list", list);
return "success";} 
else { 
return "error";
}
  }
}



<?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="Struts2" extends="struts-default"> 
  <action name="LoginAction" class="com.test.action.LoginAction" method="execute"> 
  <result name="error">/index.jsp</result> 
  <result name="success">/success.jsp</result>  
  </action>
  </package>
<constant name="struts.objectFactory" value="spring" />
</struts>  



<?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.0.xsd">


<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>

<!-- dao___sessionFactory -->
<bean id="loginDao" class="com.test.dao.loginDao">