github.com/ismailbayram/bigpicture@v0.0.0-20231225173155-e4b21f5efcff/internal/browser/javaproject/src/main/com/shashi/servlets/AdminLogoutServlet.java (about) 1 package com.shashi.servlets; 2 3 import java.io.IOException; 4 import java.io.PrintWriter; 5 6 import javax.servlet.RequestDispatcher; 7 import javax.servlet.ServletException; 8 import javax.servlet.annotation.WebServlet; 9 import javax.servlet.http.HttpServlet; 10 import javax.servlet.http.HttpServletRequest; 11 import javax.servlet.http.HttpServletResponse; 12 13 import com.shashi.constant.UserRole; 14 import com.shashi.utility.TrainUtil; 15 16 @SuppressWarnings("serial") 17 @WebServlet("/adminlogout") 18 public class AdminLogoutServlet extends HttpServlet { 19 20 /** 21 * 22 * @param req 23 * @param res 24 * @throws ServletException 25 * @throws IOException 26 */ 27 protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { 28 res.setContentType("text/html"); 29 PrintWriter pw = res.getWriter(); 30 if (TrainUtil.isLoggedIn(req, UserRole.ADMIN)) { 31 TrainUtil.logout(res); 32 RequestDispatcher rd = req.getRequestDispatcher("AdminLogin.html"); 33 rd.include(req, res); 34 pw.println("<div class='tab'><p1 class='menu'>You have been successfully logged out !</p1></div>"); 35 } else { 36 RequestDispatcher rd = req.getRequestDispatcher("AdminLogin.html"); 37 rd.include(req, res); 38 pw.println("<div class='tab'><p1 class='menu'>You are Already Logged Out !</p1></div>"); 39 } 40 } 41 }