使用cookie 记录登陆
来源:互联网 发布:软件代码模型 编辑:程序博客网 时间:2024/05/19 14:51
public static final String Constants.COOKIE_REMEMBERME_KEY="user";
public class StringUtils{
public booblean isNotEmpty(String word){
if(wrod.equals("")){
return true;
}else{
return false;
}
}
/记录客户端Cookie中
if (StringUtils.isNotEmpty(rememberMe)) {
if (rememberMe.equals("true")) {
Cookie cookie = new Cookie(Constants.COOKIE_REMEMBERME_KEY, user.getUserName() + "==" + user.getPassword());
cookie.setMaxAge(60 * 60 * 24 * 14);
cookie.setPath("/");
response.addCookie(cookie);
}
}
User curUser = (User)session.getAttribute(Constants.USER);
if(curUser==null)
{
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (Cookie cookie : cookies) {
if (Constants.COOKIE_REMEMBERME_KEY.equals(cookie.getName())) {
String value = cookie.getValue();
if (StringUtils.isNotBlank(value)) {
String[] split = value.split("==");
String userName = split[0];
String password = split[1];
try {
User user = userJdbc.getByUserName(userName);
if (null != user) {
if (user.getPassword().equalsIgnoreCase(password)) {
session.setAttribute(Constants.USER, user);
request.getSession().setAttribute("autoAuctionState", user.getAutoAuctionState());
}
}
} catch (Exception e) {
//response.sendRedirect("/index.ac");
}
} else {
//response.sendRedirect("/index.ac");
}
//response.sendRedirect("/index.ac");
}
}
}
}
// 客户端从本地查找服务器端发送过来的cookie,有没有user,如果有就把以下那个值负
<%
String userName = null;
String password = null;
Cookie[] cookies = request.getCookies();
for (int i = 0; cookies != null && i < cookies.length; i++) {
if(cookies[i].getName().equals("user")){
userName = cookies[i].getValue().split("==")[0];
password = cookies[i].getValue().split("==")[1];
}
}
if(userName == null){
name = "";
}
if(password == null){
pass = "";
}
%>
用户名:<input type="text" name="name" size="15" value="<%=userName %>" />
密码:<input type="password" name="pass" size="15" value="<%=password %>" />
记住密码:<input type="checkbox" name="ck" value="1"/>
参看:http://blog.csdn.net/Jerry_BJ/archive/2010/06/27/5697532.aspx
外部qq
<td height="30" align="center">
<a href=' http://wpa.qq.com/msgrd?V=1&Uin=309391670&Site=通达欢迎您&Menu=yes' target='_blank'>
<img src="resource/images/pa.gif" width="61" height="16" border="0" alt="点击这里给我发消息"></a></td>
- 使用cookie 记录登陆
- python使用cookie模拟登陆
- 网络爬虫-使用Cookie登陆
- web 过滤器(jsp+cookie+filter免登陆Tomcat)使用记录
- Java使用Cookie记录
- 使用Cookie登陆,保存Cookie,读取Cookie(C#)
- 使用Cookie登陆,保存Cookie,读取Cookie(C#)
- 使用cookie保存用户登陆信息
- 使用Cookie实现多少时间内不用登陆
- httpclient模拟登陆(使用js设置cookie)
- js使用cookie保存登陆信息
- 使用session和cookie实现免登陆
- Python3网络爬虫:使用Cookie-模拟登陆
- js使用cookie保存登陆信息
- 使用Cookie记录访问数
- 使用Cookie记录登录信息
- JavaScript 使用Document记录cookie
- 跨域登陆,IE下无法记录Cookie
- 不要忘记内存
- 关于PowerDesigner中几个词组
- 在javascript中使用时间戳可以防止IE缓存
- C# winForm 将窗体状态栏StatusStrip示例(显示当前时间)的方法
- 有关《网站设计大访问量应用的解决方案》的知识整理
- 使用cookie 记录登陆
- org.dom4j.Document -> org.w3c.dom.Document的转换
- 哈佛商学院要求学生必看的10部经典电影
- NoSQL数据库探讨之一 ——为什么要用非关系数据库?
- ARP协议解码详解
- Android和四大主流手机操作系统的区别联系
- 解决insmod: error inserting 'helloworld.ko': -1 Invalid module format
- [调查] 2010 年最新全球服务器市场统计分析
- .net时间格式化显示的几种方式