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");
哈哈,你犯了个低级错误,郁闷死你
写死了的,后面应该用变量。。。
--------------------------------------------------------------------------------
提问者对于答案的评价:
额....好象是没有发现。谢谢了。呵呵。下次还真要仔细点啊。
悬赏: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");
哈哈,你犯了个低级错误,郁闷死你
写死了的,后面应该用变量。。。
--------------------------------------------------------------------------------
提问者对于答案的评价:
额....好象是没有发现。谢谢了。呵呵。下次还真要仔细点啊。