package com.sugar.servlets;
import com.sugar.users.SystemUsers;
import com.sugar.users.User;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author LordNighton
*
*/
@WebServlet(name = "DeleteUserServlet", urlPatterns = {"/DeleteUserServlet"})
public class DeleteUserServlet extends HttpServlet {
protected void processRequest (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType ("text/html;charset=UTF-8");
String userToDeleteLogin = (String) request.getParameter ("delete");
SystemUsers sysUsers = (SystemUsers) request.getServletContext().getAttribute ("sysUsers");
List <User> usersList = sysUsers.getUsers();
usersList.remove (sysUsers.getUserByLogin (userToDeleteLogin));
response.sendRedirect ("protected/adminPanel.jsp");
}
@Override
protected void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
processRequest (request, response);
}
@Override
public String getServletInfo() {
return "Delete user servlet";
}
}