Example #1
0
  /**
   * Handles the HTTP <code>POST</code> method.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    User us = new User();
    us.setCluster(cluster);
    HttpSession session = request.getSession();
    LoggedIn lg = new LoggedIn();
    lg.setLoggedout();
    lg.setUsername(null);
    session.setAttribute("LoggedIn", lg);
    response.sendRedirect("index.jsp");
  }
Example #2
0
  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    HttpSession session = request.getSession();
    String username = "";
    for (Part part : request.getParts()) {
      if (part.getName().equals("message")) {
        part.delete();
        break;
      }
      String type = part.getContentType();

      if (!type.startsWith("image/")) {
        request.setAttribute("invalidType", true);
        RequestDispatcher rd = request.getRequestDispatcher("upload.jsp");
        rd.forward(request, response);
      }
      String filename = part.getSubmittedFileName();

      InputStream is = request.getPart(part.getName()).getInputStream();
      int i = is.available();

      LoggedIn lg = (LoggedIn) session.getAttribute("LoggedIn");

      if (lg.getlogedin()) {
        username = lg.getUsername();
        if (i > 0) {
          byte[] b = new byte[i + 1];
          is.read(b);
          PicModel tm = new PicModel();
          tm.setCluster(cluster);
          String description = request.getParameter("message");
          if (session.getAttribute("Location").equals("profile")) {
            tm.insertPic(b, type, filename, username, description, true);
          } else {
            tm.insertPic(b, type, filename, username, description, false);
          }
          is.close();
        }
      }
    }
    if (session.getAttribute("Location").equals("profile")) {
      response.sendRedirect("UserProfile");
    } else {
      response.sendRedirect("/InstagrimXinyue/Images/" + username);
    }
  }
Example #3
0
  /**
   * @param request The servlet request we are processing
   * @param response The servlet response we are creating
   * @param chain The filter chain we are processing
   * @exception IOException if an input/output error occurs
   * @exception ServletException if a servlet error occurs
   */
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
      throws IOException, ServletException {
    if (debug) {
      log("ProtectPages:doFilter()");
    }

    doBeforeProcessing(request, response);
    System.out.println("Doing filter");
    HttpServletRequest httpReq = (HttpServletRequest) request;
    HttpSession session = httpReq.getSession(false);
    LoggedIn li = (LoggedIn) session.getAttribute("LoggedIn");
    System.out.println("Session in filter " + session);
    if ((li == null) || (li.getlogedin() == false)) {
      System.out.println("Foward to login");
      RequestDispatcher rd = request.getRequestDispatcher("/login.jsp");
      rd.forward(request, response);
    }
    Throwable problem = null;
    try {
      chain.doFilter(request, response);
    } catch (IOException | ServletException t) {
      // If an exception is thrown somewhere down the filter chain,
      // we still want to execute our after processing, and then
      // rethrow the problem after that.
      problem = t;
    }

    doAfterProcessing(request, response);

    // If there was a problem, we want to rethrow it if it is
    // a known type, otherwise log it.
    if (problem != null) {
      if (problem instanceof ServletException) {
        throw (ServletException) problem;
      }
      if (problem instanceof IOException) {
        throw (IOException) problem;
      }
      sendProcessingError(problem, response);
    }
  }