用户在线踢人
来源:互联网 发布:淘宝一加3邀请码靠谱吗 编辑:程序博客网 时间:2024/04/28 22:47
index.jsp:
<c:if test="${sessionScopse.user == null}">
<a href="${app}/loggin.jsp">用户登录</a>
</c:if>
<c:if test="${sessionScopse.user != null}">
欢迎${requestScopse.user.username} <a href="${app}/servlet/Loggout">注销</a>
</c:if>
loggin.jsp
<h1>用户登录</h1><hr>
<form action="${app}/servlet/Login" method="post">
用户名:<input type="text" name ="username">
密码:<input type="password" name="password">
<input type="submit" value="登录">
</form>
userList.jsp
<c:if test="${user == null}">
没有访问权限
</c:if>
<c:if test="${user != null}">
<c:if test="${user.role =='user' }">
<c:forEach items="${map}" var="entry">
${entry.key}<br>
</c:forEach>
</c:if>
<c:if test="${user.role =='admin' }">
<c:forEach items="${map}" var="entry">
${entry.key}<a href="${app}/servlet/Kict?id=${entry.key}">踢人</a>
</c:forEach>
</c:if>
</c:if>
user:
public class Users implements Serializable,HttpSessionBindingListener {
private int id;
private String username;
private String password;
private String nickName;
private String role;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getNickName() {
return nickName;
}
public void setNickName(String nickName) {
this.nickName = nickName;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
public void valueBound(HttpSessionBindingEvent event) {
Map<String,HttpSession> map =(Map<String, HttpSession>) event.getSession().getServletContext().getAttribute("map");
map.put(username, event.getSession());
}
public void valueUnbound(HttpSessionBindingEvent event) {
Map<String,HttpSession> map =(Map<String, HttpSession>) event.getSession().getServletContext().getAttribute("map");
map.remove(username);
}
}
CreateMap :
public class CreateMap implements ServletContextListener {
public void contextDestroyed(ServletContextEvent arg0) {
}
public void contextInitialized(ServletContextEvent event) {
event.getServletContext().setAttribute("map", new HashMap<String, HttpSession>());
event.getServletContext().setAttribute("app",event.getServletContext().getContextPath());
}
}
Login :
public class Login extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("html/text;charset=utf-8");
//1.获取参数
String username = request.getParameter("username");
String password = request.getParameter("password");
//到数据库去查
Users users = null;
QueryRunner run = new QueryRunner(DaoUtils.getSource());
try {
users = run.query("select * from users where username=? and password=?", new BeanHandler<Users>(Users.class),username,password);
HttpSession session = request.getSession();
if(users==null){
response.getWriter().write("用户不存在");
response.sendRedirect(request.getContextPath()+"/loggin.jsp");
}else{
session.setAttribute("user", users);
response.sendRedirect(request.getContextPath()+"/userList.jsp");
}
} catch (SQLException e) {
e.printStackTrace();
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
Kict:
public class Kict extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
String username = request.getParameter("id");
//2.获取usermap,查找此名字对应的记录,找找到此人的session杀死
HttpSession session = request.getSession();
Map<String,HttpSession> map = (Map<String, HttpSession>) this.getServletContext().getAttribute("map");
if(map.containsKey(username)){
map.get(username).invalidate();
}
response.sendRedirect(request.getContextPath()+"/userList.jsp");
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
- 用户在线踢人
- spring security3 实现踢出在线用户
- spring security3 实现踢出在线用户
- apache shiro踢出用户和获取所有在线用户
- apache shiro踢出用户和获取所有在线用户
- linux查看在线用户并踢出用户
- linux查看在线用户并踢出用户
- day18 监听器 统计在线人数,定时销毁超时session,钝化活化session,在线列表显示和踢人功能防止用户自动登录,在线支付
- java鬼混笔记:shiro 10、在线用户、踢人下线、唯一登录
- PHP处理在线用户
- 在线用户统计
- 在线用户统计
- LotusScript获得在线用户
- 在线用户统计
- 用户在线统计实现
- LotusScript获得在线用户
- 判断用户是否在线
- 统计在线用户
- Oracle DB 使用RMAN创建备份1
- [HAOI2007]反素数ant
- [Eclipse报错] The type XXX cannot be resolved. It is indirectly referenced from required .class files
- 《google时代的工作方法》书摘
- Ubuntu12.04 64bit 下载android4.3源代码
- 用户在线踢人
- 【收藏】2014各大网络公司校招笔试题
- cocos2dx kazmath 分析
- java实现信号量
- [SmartOJ1902]恶搞的短信
- 顺序表的删除3
- C#/Net代码精简优化技巧(3)
- C++访问LUA中的函数
- 快速排序(三)