有没有人能帮我看看我这个loginAction有什么错误啊

XD010 2010-06-03 09:29:54
package com.stuman.web.struts.action;

import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.beanutils.BeanUtilsBean;
import org.apache.struts.action.Action;
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 org.apache.struts.action.ActionMessages;
import org.apache.struts.validator.DynaValidatorForm;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;

import com.stuman.dao.hibernate.HibernateUtil;
import com.stuman.domain.Admin;
import com.stuman.domain.Student;
import com.stuman.domain.Teacher;
import com.stuman.web.struts.form.LoginForm;

public class LoginAction extends Action {
private BeanUtilsBean beanUtilsBean;

public LoginAction() {
this.beanUtilsBean = new BeanUtilsBean();
}



/**
* Method execute
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
* @throws UnsupportedEncodingException
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws UnsupportedEncodingException {

// TODO Auto-generated method stub

HttpSession session = request.getSession();
Session s = HibernateUtil.currentSession();
LoginForm loginForm = new LoginForm();
DynaValidatorForm dform = (DynaValidatorForm) form;
try {
this.getBeanUtilsBean().copyProperties(loginForm, dform);
} catch (IllegalAccessException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (InvocationTargetException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

String sort = loginForm.getSort();
String username = loginForm.getUsername();

String password = loginForm.getPassword();
int loginSort = Integer.parseInt(sort);
String[] userlist = new String[2];
userlist[0] = username;
userlist[1] = password;
List list = new ArrayList();
try {

HibernateUtil.beginTransaction();
String str = new String();
switch (loginSort) {
case 1:
str = " from Student as stu where stu.name=:stuName and stu.password=:stuPassword";
Query query = s.createQuery(str);
System.out.println(username + " " + password);
query.setString("stuName", username);
query.setString("stuPassword", password);
list = query.list();

if (list.size() > 0) {
request.getSession().setAttribute("stuid",
((Student) list.get(0)).getId());
request.getSession().setAttribute("deptment",
((Student) list.get(0)).getDepartment());
s.close();
return mapping.findForward("studentLoginsuccess");
} else

break;
case 2:
str = " from Teacher tea where tea.name =? and tea.password ='"
+ password + "'";

Query query2 = s.createQuery(str);
// System.out.println(username + " " + password);
query2.setString(0, username);
list = query2.list();
if (list.size() > 0) {
request.getSession().setAttribute("teaid",
((Teacher) list.get(0)).getId());
request.getSession().setAttribute("teacherId",
((Teacher) list.get(0)).getId());
s.close();
return mapping.findForward("teacherLoginsuccess");
} else
break;
case 3:
str = " from Admin admin where admin.name = ? and admin.password ='"
+ password + "'";
// System.out.println(username + " " + password);
Query query3 = s.createQuery(str);
query3.setString(0, username);
list = query3.list();
if (list.size() > 0) {
request.getSession().setAttribute("id",
((Admin) list.get(0)).getId());
s.close();
return mapping.findForward("adminLoginsuccess");
} else
break;
default:
break;
}
} catch (HibernateException e) {
e.printStackTrace();
} finally {
s.close();
}
ActionMessages errors = new ActionMessages();
errors.add("login error", new ActionMessage("login.error"));
saveErrors(request, errors);
return mapping.getInputForward();

}

public BeanUtilsBean getBeanUtilsBean() {
return beanUtilsBean;
}
}
...全文
82 5 打赏 收藏 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zuoguodang 2010-06-03
  • 打赏
  • 举报
回复
同意楼上说的
XD010 2010-06-03
  • 打赏
  • 举报
回复
没问题啊,就是运行的时候错误提示是username cannot be resolved
若鱼1919 2010-06-03
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 goldenfish1919 的回复:]
引用 1 楼 goldenfish1919 的回复:
应该不会有


我觉得也是!

楼下的,你说呢?
[/Quote]

同意!
若鱼1919 2010-06-03
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 goldenfish1919 的回复:]
应该不会有
[/Quote]

我觉得也是!

楼下的,你说呢?
若鱼1919 2010-06-03
  • 打赏
  • 举报
回复
应该不会有

62,620

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧