Package com.barsoft.memepost.servlets

Source Code of com.barsoft.memepost.servlets.DislikePostServlet

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.barsoft.memepost.servlets;

import com.barsoft.memepost.entities.Post;
import com.barsoft.memepost.entities.User;
import com.barsoft.memepost.entities.Users;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
*
* @author maks
*/
public class DislikePostServlet extends HttpServlet {

     @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         request.setCharacterEncoding("UTF-8");
        HttpSession sess = request.getSession();
        User curuser = (User) sess.getAttribute("curuser");
        String curpost = (String) request.getParameter("id");
        Users users = (Users) this.getServletContext().getAttribute("users");

        boolean stop=false;
        for (User u : users.getUsers().keySet()) {
            for (Post p : ((List<Post>) users.getUsers().get(u))) {
                if (p.getId() == Integer.parseInt(curpost)) {
                    if (p.getDislikers().getUsers().keySet().contains(curuser)) {
                        p.getDislikers().getUsers().remove(curuser);

                    } else {
                        p.getDislikers().getUsers().put(curuser, ((List<Post>) users.getUsers().get(curuser)));

                    }
                    response.sendRedirect(request.getContextPath() + "/home.jsp");
                   return;
                }
               
            }

        }

        response.sendRedirect(request.getContextPath() + "/home.jsp");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
TOP

Related Classes of com.barsoft.memepost.servlets.DislikePostServlet

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.