java使用Cookie判断用户登录情况的方法
作者:Sunny* 时间:2021-11-28 15:12:40
本文实例为大家分享了java使用Cookie判断用户登录情况的方法,供大家参考,具体内容如下
1.判断是否登录
public boolean isLogin() {
Set<Cookie> cookies = this.browser.getCookies();
String JSESSIONIDID = "JSESSIONID";
String sessionIdID = "sessionId";
String loginID = "login";
String JSESSIONIDIDValue = "";
String sessionIdValue = "";
String loginValue = "";
for (Cookie c:cookies) {
logger.info(c.getName() + ": " + c.getValue());
if (c.getName().equals(JSESSIONIDID)) {
JSESSIONIDIDValue = c.getValue();
} else if(c.getName().equals(sessionIdID)) {
sessionIdValue = c.getValue();
} else if (c.getName().equals(loginID)) {
loginValue = c.getValue();
}
}
if ( JSESSIONIDIDValue.equals(sessionIdValue) & loginValue.equals("login")) {
return true;
} else {
return false;
}
}
2.页面登录cookie
来源:http://www.cnblogs.com/sunny-sl/p/8064801.html
标签:java,Cookie,用户登录
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java中获取文件大小的详解及实例代码
2023-02-27 08:12:27
![](https://img.aspxhome.com/file/2023/2/67432_0s.png)
Java开发之spring security实现基于MongoDB的认证功能
2022-06-29 15:52:32
java实现图书检索系统
2023-08-18 20:08:50
![](https://img.aspxhome.com/file/2023/1/66681_0s.jpg)
Web容器启动过程中如何执行Java类
2022-10-01 19:49:10
springboot使用JPA时间类型进行模糊查询的方法
2023-10-26 21:59:02
![](https://img.aspxhome.com/file/2023/5/81295_0s.png)
如何写好一个Spring组件的实现步骤
2023-01-08 20:24:12
![](https://img.aspxhome.com/file/2023/2/75032_0s.jpg)
java面试题之try中含return语句时代码的执行顺序详解
2023-11-24 07:34:16
![](https://img.aspxhome.com/file/2023/3/59913_0s.png)
spring-boot中使用spring-boot-devtools的实现代码
2021-10-09 13:31:32
Mybatis通过Spring完成代理类注入的流程分析
2023-10-25 00:55:55
![](https://img.aspxhome.com/file/2023/5/70575_0s.png)
Java源码解析之ClassLoader
2022-06-14 06:07:47
Java并发编程之线程创建介绍
2021-11-14 13:55:40
java语言图形用户登录界面代码
2021-09-11 23:19:34
![](https://img.aspxhome.com/file/2023/6/64216_0s.jpg)
WPF自定义控件的实现
2021-07-06 02:34:11
![](https://img.aspxhome.com/file/2023/5/74825_0s.jpg)
探讨:将两个链表非降序合并为一个链表并依然有序的实现方法
2023-06-23 01:41:38
C#实现收发邮件功能
2021-09-20 19:40:46
java 中HashCode重复的可能性
2021-09-13 17:38:05
Spring原生Rpc六种的正确打开方式实现示例
2021-06-23 19:35:03
![](https://img.aspxhome.com/file/2023/7/77337_0s.png)
SpringBoot项目的logback日志配置(包括打印mybatis的sql语句)
2021-08-24 02:15:22
![](https://img.aspxhome.com/file/2023/7/63767_0s.png)
spring boot整合Shiro实现单点登录的示例代码
2023-04-07 01:17:56
![](https://img.aspxhome.com/file/2023/5/65145_0s.png)
手动模拟JDK动态代理的方法
2023-03-23 00:49:03