@Override
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, java.io.IOException {

    try {

      UserBean user = new UserBean();

      user.setQuery(
          "SELECT * FROM creditcard WHERE number='" + request.getParameter("cardnumber") + "'");

      user = UserDAO.login(user);

      boolean coba = user.isValid();

      if (user.isValid()) {

        response.getWriter().print(true);
      } else response.getWriter().print(false);

    } catch (Throwable theException) {
      System.out.println(theException);
    }
  }
コード例 #2
0
  @Override
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, java.io.IOException {

    try {
      UserBean user = new UserBean();
      user.setType("getfrozen");
      if (request.getParameter("sort") != null) {
        String sort = (String) request.getParameter("sort");
        if (sort.equals("namabarang")) {
          user.setQuery("SELECT * FROM Barang WHERE Kategori = 'Frozen Food' order by NamaBarang");
        } else if (sort.equals("harga")) {
          user.setQuery("SELECT * FROM Barang WHERE Kategori = 'Frozen Food' order by Harga");
        } else if (sort.equals("urutkan")) {
          user.setQuery("SELECT * FROM Barang WHERE Kategori = 'Frozen Food'");
        }
      } else {
        user.setQuery("SELECT * FROM Barang WHERE Kategori = 'Frozen Food'");
      }
      user = UserDAO.login(user);
      ArrayList<Barang> frozenes = new ArrayList<Barang>();
      frozenes = user.getfrozen();
      HttpSession session = request.getSession(true);
      session.setAttribute("jumlahfrozen", frozenes.size());
      for (int i = 0; i < frozenes.size(); i++) {
        String bnama = "fnama" + (i + 1);
        String bid = "fid" + (i + 1);
        String bharga = "fharga" + (i + 1);
        String bkategori = "fkategori" + (i + 1);
        String bjumlah = "fjumlah" + (i + 1);
        session.setAttribute(bnama, frozenes.get(i).getNama());
        session.setAttribute(bid, frozenes.get(i).getId());
        session.setAttribute(bharga, frozenes.get(i).getHarga());
        session.setAttribute(bkategori, frozenes.get(i).getKategori());
        session.setAttribute(bjumlah, frozenes.get(i).getJumlah());
      }

      response.sendRedirect("Frozen.jsp?f=1&l=10");
    } catch (Throwable theException) {
      System.out.println(theException);
    }
  }
コード例 #3
0
ファイル: UserServlet.java プロジェクト: sorako/kotemaru
  public void doGet(HttpServletRequest req, HttpServletResponse res)
      throws IOException, ServletException {
    UserService userService = UserServiceFactory.getUserService();
    String retUrl = req.getParameter("url");
    if (retUrl == null) retUrl = "/";

    String pathInfo = req.getPathInfo();
    if (pathInfo.equals("/current")) {
      User user = userService.getCurrentUser();
      if (user == null) {
        res.setStatus(401);
        res.setContentType("text/plain; charset=utf-8");
        res.getWriter().write("Not login");
        return;
      }

      UserBean ub = getByEmail(user.getEmail());

      res.setContentType("application/json; charset=utf-8");
      res.setHeader("Cache-control", "no-cache");
      res.getWriter().write("{\"email\":\"" + user.getEmail() + "\"");
      if (ub != null) {
        res.getWriter().write(",\"nickName\":\"" + ub.getNickName() + "\"");
        res.getWriter().write(",\"isRegister\":true");
      } else {
        String nn = user.getNickname();
        if (nn == null) nn = user.getEmail();
        res.getWriter().write(",\"nickName\":\"" + nn + "\"");
        res.getWriter().write(",\"isRegister\":false");
      }
      res.getWriter().write("}");

    } else if (pathInfo.equals("/login")) {
      String url = userService.createLoginURL(retUrl);
      res.sendRedirect(url);
    } else if (pathInfo.equals("/logout")) {
      String url = userService.createLogoutURL(retUrl);
      res.sendRedirect(url);
    } else if (pathInfo.equals("/register")) {
      User user = userService.getCurrentUser();
      if (user == null) {
        res.setStatus(401);
        res.setContentType("text/plain; charset=utf-8");
        res.getWriter().write("Not login");
        return;
      }

      String nickName = req.getParameter("nickName");
      UserBean ub = getByNeckName(nickName);
      if (ub != null) {
        res.setStatus(403);
        res.setContentType("text/plain; charset=utf-8");
        res.getWriter().write("ニックネーム(" + nickName + ")は既に使われています。");
        return;
      }

      ub = new UserBean();
      ub.setEmail(user.getEmail());
      ub.setNickName(nickName);
      usbs.put(user.getEmail(), ub);
      ursbs.put(nickName, ub);

      FileBean fb = new FileBean();
      fb.setParentName("");
      fb.setLastName(nickName);
      fb.setDirectory(true);
      fb.setLastModified(System.currentTimeMillis());
      fb.setOwner(user.getEmail());
      fb.setNickName(nickName);
      sbs.put("/" + nickName, fb);

      res.sendRedirect(retUrl);
    }
  }