为了账号安全,请及时绑定邮箱和手机立即绑定

为啥我创建的Cookie老是有问题

<%@page import="java.net.CookieHandler"%>
<%@page import="org.omg.CORBA.RepositoryIdHelper"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page  import="java.util.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>登录成功</h1>
<hr>
<br>
<br>
<br>
<br>
<%
           //判断是否选择了记住登录状态
            String[]  isUserCookie=request.getParamerterValues("isUserCookie");
            if( isUserCookie!=null&&isUserCookie.length>0)
            {
             String username=request.getParmarterValue("username");
             String passward=request.getParmarterValue("passward");
             Cookie usernamecookie=new Cookie("username",username);
             Cookie passwardcookie=new  Cookie("passward",passward);
             usernamecookie.setMaxage(864000);
             passwardcookie.setMaxage(864000);
             response.addCookie(usernamecookie);
             response.addCookie(passwardcookie);
            }
            else{
             
             Cookie[]  cookie=request.getCookie();
             if(cookie!=null&&cookie.length>0)
             {
               for(Cookie  c:cookie)
               {
                if(c.getName().equals("username")||c.getName()/equals("passward"))
                {
                 c.setMaxage(0);
                 response.addCookie(c);
                
                } 
               }
             }
          
            }
  
 

%>


<a href="users.jsp" target="_Blank">查看已经登录的用户信息</a>
</body>
</html>_


正在回答

1 回答

  if(c.getName().equals("username")||c.getName()/equals("passward"))   这一行是不小心输错了吧 

c.getName()/equals("passward"))  方法调用改为“.”c.getName().equals("passward"))

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

为啥我创建的Cookie老是有问题

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信