• 使用cookie 记录登陆


     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"/> &nbsp;

    参看: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&amp;Uin=309391670&amp;Site=通达欢迎您&amp;Menu=yes' target='_blank'>

    <img src="resource/images/pa.gif" width="61" height="16" border="0" alt="点击这里给我发消息"></a></td>

  • 相关阅读:
    Ajax学习笔记2客户端访问WebService(上)
    在 .NET Framework 2.0 中未处理的异常导致基于 ASP.NET 的应用程序意外退出(我加了点注释)
    想用JS写一段鼠标拖拽调整图片大小的代码(未完)
    key/value/index 类型定义for .net
    ReadOnly属性对TEXTBOX的状态保存有影响?
    软件开发工具名称集锦(无下载地址,收集中...)
    AjaxPro让.NET的AjaxPro变得简单
    Ajax学习笔记(15):使用ASP.NET AJAX提供的Authentication Service
    在.NET中使用Newtonsoft.Json转换,读取,写入
    Orcale的 rownum
  • 原文地址:https://www.cnblogs.com/java20130726/p/3218421.html
Copyright © 2020-2023  润新知