LoginAction.java
上传用户:jishiqi_cj
上传日期:2022-08-08
资源大小:24765k
文件大小:1k
源码类别:

Java编程

开发平台:

Java

  1. package classmate;
  2. import org.apache.struts.action.Action;
  3. import org.apache.struts.action.ActionForm;
  4. import org.apache.struts.action.ActionForward;
  5. import org.apache.struts.action.ActionMapping;
  6. import org.apache.struts.action.ActionMessages;
  7. import org.apache.struts.action.ActionMessage;
  8. import javax.servlet.ServletContext;
  9. import javax.sql.DataSource;
  10. import javax.servlet.http.*;
  11. public final class LoginAction extends Action{  
  12. public ActionForward execute(
  13. ActionMapping mapping,
  14. ActionForm form,
  15. HttpServletRequest request,  
  16. HttpServletResponse response) throws Exception {
  17.     UserForm userform = (UserForm) form;         
  18. String name = userform.getName();
  19. String psw = userform.getPsw();
  20.     ServletContext context = servlet.getServletContext();
  21. DataSource dataSource = (DataSource)context.getAttribute("oracleDB1");
  22.         DBUser dbuser = new DBUser(dataSource);
  23.         HttpSession session = request.getSession();
  24.         
  25.         if (!dbuser.checkUser(name,psw)) {
  26. ActionMessages errors = new ActionMessages();
  27. errors.add(ActionMessages.GLOBAL_MESSAGE,
  28. new ActionMessage("label.deny"));
  29. if (!errors.isEmpty()) {
  30. saveErrors(request, errors);
  31.    return  mapping.findForward("failed");  //登陆失败
  32. }
  33. else{
  34.       return (mapping.findForward("successed"));//登陆成功
  35. }
  36. }
  37. }