天天看點

使用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" alt="點選這裡給我發消息"></a></td>