java ssh 登录功能,ssh框架调整,做登录的功能?

当前位置:我的异常网» Java Web开发 » ssh框架调整,做登录的功能?

ssh框架调整,做登录的功能?

www.myexceptions.net  网友分享于:2013-09-11  浏览:12次

ssh框架整合,做登录的功能??

用struts2.xml + spring + hibernate3.0 做登录的功能,总是报错,小弟第一次用3个框架整合,初学者,希望得到各位前辈的指点

//web.xml applicationContext.xml默认放在src下

org.springframework.web.context.ContextLoaderListener

contextConfigLocation

/WEB-INF/classes/applicationContext.xml

//applicationContext.xml里面的配置文件

//dao层

//用户登录

public int LoginUser(String userName,String userPassword){

String hql = "from Users where userName='"+userName+"' and userPassword='"+userPassword+"' ";

Query query = this.getSession().createQuery(hql);

List userList = query.list();

return userList.size();

}

//service层

private String userName;

private String userPassword;

private LoginUserInfo info;

private LoginUserDao userdao;

public String execute(){

try{

LoginUserDao dao = new LoginUserDao();

int i = dao.LoginUser(this.getUserName(), this.getUserPassword());

System.out.println(this.getUserName());

if(i > 0 ){

return "success";

}

else{

return "error";

}

}

catch(Exception ex){

ex.printStackTrace();

}

return "error";

}

//struts.xml

/su.jsp

/error.jsp

报错信息:

java.lang.NullPointerException

at org.springframework.orm.hibernate3.support.HibernateDaoSupport.getSession(HibernateDaoSupport.java:143)

at com.jy.dao.LoginUserDao.LoginUser(LoginUserDao.java:19)

at com.jy.service.LoginUserService.execute(LoginUserService.java:18)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

------解决方案--------------------

登录dao层

public int LoginUser(String userName,String userPassword){

List list = this.getHibernateTemplate().find("from Users where userName='"+userName+"' and userPassword='"+userPassword+"' ");

return list.size();

}

action层

try{

String [] name = {"applicationContext.xml"};

BeanFactory bean = new ClassPathXmlApplicationContext(name);

LoginUserService login = (LoginUserService)bean.getBean("loginservice");

int i = login.getUserdao().LoginUser(userName, userPassword);

if(i > 0 ){

return "success";

}

else{

return "error";

}

文章评论

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值