LoginAction.java
上传用户:nbxinmin
上传日期:2021-10-09
资源大小:46k
文件大小:2k
源码类别:

Internet/IE编程

开发平台:

Java

  1. package com.xdf.exams.web.action;
  2. import java.util.Date;
  3. import javax.servlet.http.HttpServletRequest;
  4. import javax.servlet.http.HttpServletResponse;
  5. import javax.servlet.http.HttpSession;
  6. import org.apache.struts.action.Action;
  7. import org.apache.struts.action.ActionForm;
  8. import org.apache.struts.action.ActionForward;
  9. import org.apache.struts.action.ActionMapping;
  10. import com.xdf.exams.bean.Loginlog;
  11. import com.xdf.exams.bean.Student;
  12. import com.xdf.exams.bean.Teacher;
  13. import com.xdf.exams.bo.BOFactory;
  14. import com.xdf.exams.bo.ILogService;
  15. import com.xdf.exams.web.form.LoginForm;
  16. /** 
  17.  * MyEclipse Struts
  18.  * Creation date: 04-04-2007
  19.  * 
  20.  * XDoclet definition:
  21.  * @struts.action validate="true"
  22.  */
  23. public class LoginAction extends Action {
  24. /** 
  25.  * Method execute
  26.  * @param mapping
  27.  * @param form
  28.  * @param request
  29.  * @param response
  30.  * @return ActionForward
  31.  */
  32. public ActionForward execute(ActionMapping mapping, ActionForm form,
  33. HttpServletRequest request, HttpServletResponse response) {
  34. LoginForm loginForm = (LoginForm)form;
  35. ILogService ser = BOFactory.getLogService();
  36. Loginlog log = new Loginlog();
  37. log.setIp(request.getRemoteAddr());
  38. log.setLogtime(new Date());
  39. log.setUsername(loginForm.getUsername());
  40. HttpSession session = request.getSession();
  41. ActionForward forward = null;
  42. try {
  43. if(loginForm.getRole()==0) {
  44. log.setIsteacher(0);
  45. Student s = ser.studentlogin(loginForm.getUsername(),loginForm.getPassword());
  46. if(s!=null) {
  47. session.setAttribute("student",s);
  48. log.setSuccess(1);
  49. forward = mapping.findForward("student");
  50. }else {
  51. request.setAttribute("message","登陆失败");
  52. forward = mapping.findForward("index");
  53. }
  54. }else {
  55. log.setIsteacher(1);
  56. Teacher t = ser.teacherlogin(loginForm.getUsername(),loginForm.getPassword());
  57. if(t!=null) {
  58. session.setAttribute("teacher",t);
  59. log.setSuccess(1);
  60. forward = mapping.findForward("teacher");
  61. }else {
  62. request.setAttribute("message","登陆失败");
  63. forward = mapping.findForward("index");
  64. }
  65. }
  66. ser.addlog(log);
  67. } catch (RuntimeException e) {
  68. e.printStackTrace();
  69. request.setAttribute("message","登陆失败");
  70. forward = mapping.findForward("index");
  71. }
  72. return forward;
  73. }
  74. }