Map map=(Map) getServletContext().getAttribute("users");

package com.tfy.heima.servlet;


import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


public class KickServlet extends HttpServlet {


public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {


response.setContentType("text/html;charset=UTF-8");
PrintWriter out=response.getWriter();
String username=request.getParameter("username");

username=new String(username.getBytes("ISO-8859-1"),"UTF-8");
Map<String, HttpSession> map=(Map<String, HttpSession>) getServletContext().getAttribute("users");

HttpSession session=map.get(username);
if(session!=null){
session.removeAttribute("user");
map.remove(username);
}
out.write("踢出成功");
}


public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {


doGet(request, response);
}


}

你可能感兴趣的:(Map map=(Map) getServletContext().getAttribute("users");)