コード例 #1
0
  /**
   * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    Connection connection;
    try {
      connection = OnlineStoreDB.makeConnection();
      String mail = request.getParameter("mail");
      String password = request.getParameter("password");

      Member user = new Member();
      user = MemberDAO.findMember(connection, mail, password); // find that user in DB

      System.err.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Login USER : "******"currentSessionUser", user);
        session.setAttribute("currentSessionUserId", user.getId());
        session.setAttribute("currentSessionUserFirstName", user.getFirstname());
        session.setAttribute("currentSessionUserLastName", user.getLastname());
        response.sendRedirect("userLogged.jsp"); // logged-in page
      } else {
        response.sendRedirect("invalidLogin.jsp"); // error login
      }
    } catch (Throwable theException) {
      System.out.println(theException);
    }
  }
コード例 #2
0
  private MemberModel() {
    // init memberMap
    memberMap = new HashMap<>();
    // init entitledMap (1 to many relation between memberID and BookNumber)
    entitledMap = new HashMap<>();
    boolean readFlag = false;
    ObjectInputStream oin = null;
    Member tm;
    String[] sa = new String[3];
    try {
      oin = new ObjectInputStream(new FileInputStream("members1.dat"));
      readFlag = true;
    } catch (Exception e) {
      e.printStackTrace();
    }
    // read in from file
    while (readFlag) {
      try {
        // Read a member data from inputstream
        // Structure for reading
        // __________________________________________________________
        // |String|String|String|Boolean or Double|ArrayList<String>|
        // ----------------------------------------------------------

        sa[ID_INDEX] = oin.readUTF();
        sa[TITLE_INDEX] = oin.readUTF();
        sa[PHONENO_INDEX] = oin.readUTF();
        if (sa[ID_INDEX].indexOf("STA") != -1) {
          tm = new Staff(sa[ID_INDEX], sa[TITLE_INDEX], sa[PHONENO_INDEX]);
          ((Staff) tm).setBookOverdue(oin.readBoolean());
        } else {
          tm = new Student(sa[ID_INDEX], sa[TITLE_INDEX], sa[PHONENO_INDEX]);
          ((Student) tm).setFinesOwing(oin.readDouble());
        }
        // Raw data map without relationship to book
        memberMap.put(tm.getMemberID(), tm);
        // Map for storing relation
        entitledMap.put(tm.getMemberID(), (ArrayList<String>) oin.readObject());
      } catch (EOFException e) {
        Log.e(e.getMessage());
        readFlag = false;
      } catch (Exception e) {
        Log.e(e.getMessage());
      }
    }
    try {
      oin.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
コード例 #3
0
ファイル: Group.java プロジェクト: SmallLars/esadb
  public boolean isMember(Member member, boolean forceMaleFemale) {
    switch (gender) {
      case ANY:
        if (forceMaleFemale) return false;
        break;
      case MALE:
        if (member.isFemale()) return false;
        break;
      case FEMALE:
        if (member.isMale()) return false;
        break;
    }

    if (from > member.getBirthYear()) return false;
    if (to < member.getBirthYear()) return false;

    return true;
  }
コード例 #4
0
  /** save To save members' information into a binary file */
  public void save() {
    ObjectOutputStream oout = null;
    Member tm;
    ArrayList<String> booksBorrowed = new ArrayList<String>();
    try {
      oout = new ObjectOutputStream(new FileOutputStream("members1.dat"));
      // Loop through memberMap and process each entry
      // Structure for writing
      // __________________________________________________________
      // |String|String|String|Boolean or Double|ArrayList<String>|
      // ----------------------------------------------------------

      for (Map.Entry<String, Member> entry : memberMap.entrySet()) {
        tm = entry.getValue();
        oout.writeUTF(tm.getMemberID());
        oout.writeUTF(tm.getName());
        oout.writeUTF(tm.getPhoneNumber());
        if (tm instanceof Staff) {
          oout.writeBoolean(((Staff) tm).isBookOverdue());
        } else {
          oout.writeDouble(((Student) tm).getFinesOwing());
        }
        for (LibraryBook b : tm.getBooklist()) {
          booksBorrowed.add(b.getBookNumber());
        }
        oout.writeObject(booksBorrowed);
      }
    } catch (Exception e) {
      Log.e(e.getMessage());
    } finally {
      try {
        oout.close();
      } catch (IOException e) {
        Log.e(e.getMessage());
      }
    }
  }