hibernate出错

SSH2的问题,超级郁闷!
悬赏:5 发布时间:2008-11-27 提问人:coolstar648 (初级程序员)
本来打算给自己写个个人主页,没想到,郁闷死.一个登录竟然搞了半天没搞定.不知道到底哪里有问题,debug也很久,很郁闷!


由于比较大,所以就简单的发一些吧,反正是可以跑起来的,我就帖点重要部分的代码好了。只给出部分函数:

首先:DAO层


Java代码
public boolean findUserByLNameAndPwd(String loginName, String passWord)
throws RuntimeException {
boolean flag = false;
String hql = "from User as u where u.loginName=:Name and u.passWord=:Word";
Query query = this.getSession().createQuery(hql);
query.setParameter("Name", "loginName");
query.setParameter("Word", "passWord");
List list = query.list();
if(list.size()>0){
flag = true;
}
return flag;
}

public boolean findUserByLNameAndPwd(String loginName, String passWord)
throws RuntimeException {
boolean flag = false;
String hql = "from User as u where u.loginName=:Name and u.passWord=:Word";
Query query = this.getSession().createQuery(hql);
query.setParameter("Name", "loginName");
query.setParameter("Word", "passWord");
List list = query.list();
if(list.size()>0){
flag = true;
}
return flag;
}

再services层
Java代码
public boolean checkUser(String loginName, String passWord)
throws RuntimeException {
return userDao.findUserByLNameAndPwd(loginName, passWord);
}

public boolean checkUser(String loginName, String passWord)
throws RuntimeException {
return userDao.findUserByLNameAndPwd(loginName, passWord);
}


在Action册

Java代码
public String userLogin() throws Exception {

String result = null;
try {
boolean flag = userServices.checkUser(user.getLoginName(), user.getPassWord());
if (flag) {
result = "success";
} else {
this.setTip("<font color='red'>对不起您的帐号或密码有误!</font>");
result = "noUser";
}
} catch (Exception e) {
this.setTip("<font color='red'>对不起,系统出现故障,请稍后再登录!</font>");
e.printStackTrace();
result = "noUser";
}
return result;
}

public String userLogin() throws Exception {

String result = null;
try {
boolean flag = userServices.checkUser(user.getLoginName(), user.getPassWord());
if (flag) {
result = "success";
} else {
this.setTip("<font color='red'>对不起您的帐号或密码有误!</font>");
result = "noUser";
}
} catch (Exception e) {
this.setTip("<font color='red'>对不起,系统出现故障,请稍后再登录!</font>");
e.printStackTrace();
result = "noUser";
}
return result;
}

最后:jsp文件.
Java代码
<body>
<s:form action="/user/userLogin.action" method="post">
<table align="center">
<tr>
<th colspan="3">
<h3>欢迎登录</h3>
</th>
</tr>
<tr>
<td colspan="3">
<s:property value="tip" escape="false"/>
</td>
</tr>
<tr>
<td>用户名:</td>
<td>
<input type="text" name="user.loginName"/>
</td>
</tr>
<tr>
<td>密码:</td>
<td>
<input type="password" name="user.passWord"/>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="登录">
<a href=#>注册</a>
</td>
</tr>
</table>
</s:form>
</body>
</html>

<body>
<s:form action="/user/userLogin.action" method="post">
<table align="center">
<tr>
<th colspan="3">
<h3>欢迎登录</h3>
</th>
</tr>
<tr>
<td colspan="3">
<s:property value="tip" escape="false"/>
</td>
</tr>
<tr>
<td>用户名:</td>
<td>
<input type="text" name="user.loginName"/>
</td>
</tr>
<tr>
<td>密码:</td>
<td>
<input type="password" name="user.passWord"/>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="登录">
<a href=#>注册</a>
</td>
</tr>
</table>
</s:form>
</body>
</html>

Struts2的配置文件:
Java代码
<struts>
<package name="user" extends="struts-default" namespace="/user">

<action name="userLogin" class="com.gzz.user.action.LoginAction" method="userLogin">
<result name="success">/jsp/manage/welcome.jsp</result>
<result name="noUser">/jsp/manage/login.jsp</result>
</action></struts>


<struts>
<package name="user" extends="struts-default" namespace="/user">

<action name="userLogin" class="com.gzz.user.action.LoginAction" method="userLogin">
<result name="success">/jsp/manage/welcome.jsp</result>
<result name="noUser">/jsp/manage/login.jsp</result>
</action></struts>



问题是,不管我写没有写密码,不管有没有写对,总是返回"密码错误或者用户名错误",郁闷啊....
采纳的答案
2008-11-27 hkliya (初级程序员)
6. query.setParameter("Name", "loginName");
7. query.setParameter("Word", "passWord");

哈哈,你犯了个低级错误,郁闷死你
写死了的,后面应该用变量。。。

--------------------------------------------------------------------------------
提问者对于答案的评价:
额....好象是没有发现。谢谢了。呵呵。下次还真要仔细点啊。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
毕业设计,基于SpringBoot+Vue+MySQL开发的纺织品企业财务管理系统,源码+数据库+毕业论文+视频演示 在如今社会上,关于信息上面的处理,没有任何一个企业或者个人会忽视,如何让信息急速传递,并且归档储存查询,采用之前的纸张记录模式已经不符合当前使用要求了。所以,对纺织品企业财务信息管理的提升,也为了对纺织品企业财务信息进行更好的维护,纺织品企业财务管理系统的出现就变得水到渠成不可缺少。通过对纺织品企业财务管理系统的开发,不仅仅可以学以致用,让学到的知识变成成果出现,也强化了知识记忆,扩大了知识储备,是提升自我的一种很好的方法。通过具体的开发,对整个软件开发的过程熟练掌握,不论是前期的设计,还是后续的编码测试,都有了很深刻的认知。 纺织品企业财务管理系统通过MySQL数据库与Spring Boot框架进行开发,纺织品企业财务管理系统能够实现对财务人员,员工,收费信息,支出信息,薪资信息,留言信息,报销信息等信息的管理。 通过纺织品企业财务管理系统对相关信息的处理,让信息处理变的更加的系统,更加的规范,这是一个必然的结果。已经处理好的信息,不管是用来查找,还是分析,在效率上都会成倍的提高,让计算机变得更加符合生产需要,变成人们不可缺少的一种信息处理工具,实现了绿色办公,节省社会资源,为环境保护也做了力所能及的贡献。 关键字:纺织品企业财务管理系统,薪资信息,报销信息;SpringBoot
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值