随笔 - 35,  文章 - 0,  评论 - 1,  阅读 - 97966

1.jsp页面:

 


 
  1. <% String flag = (String)session.getAttribute("flag")==null?"":(String)session.getAttribute("flag");  
  2.    
  3. String name = "";  
  4. String password = "";  
  5. try{   
  6.     Cookie[] cookies=request.getCookies();   
  7.     if(cookies!=null){   
  8.     for(int i=0;i<cookies.length;i++){   
  9.         if(cookies[i].getName().equals("cookie_user")){   
  10.         String value =  cookies[i].getValue();  
  11.         if(value!=null&&!"".equals(value)){  
  12.             name=cookies[i].getValue().split("-")[0];   
  13.             if(cookies[i].getValue().split("-")[1]!=null && !cookies[i].getValue().split("-")[1].equals("null")){  
  14.      password=cookies[i].getValue().split("-")[1];   
  15.              }  
  16.                         
  17.             }  
  18.             }   
  19.         request.setAttribute("name",name);   
  20.         request.setAttribute("passward",password);   
  21.     }   
  22.     }   
  23. }catch(Exception e){   
  24.     e.printStackTrace();   
  25. }   
  26. %>   
  27. <body>  
  28. <div id="logo"><img src="<%=request.getContextPath() %>/frontsite/Images/Logo.jpg" width="244" height="44" alt="" /></div>  
  29. <div id="loginfrm">  
  30. <form action="<%=request.getContextPath() %>/frontsite/login.do?method=login" method="post" id="forms" onsubmit="checkForm();return false;">  
  31.     <div class="frm">  
  32.         <ul>  
  33.             <li class="l1">用户名:</li>  
  34.             <li class="l2"><input name="login_id" type="text" id="login_id" class="input" value="<%=name %>"/></li>  
  35.             <li class="l3">* 最大限度为20字节</li>  
  36.             <li class="l1">密码:</li>  
  37.             <li class="l2"><input name="login_pwd" type="password" id="login_pwd" class="input" value="<%=password %>"/></li>  
  38.             <li class="l3">* 最大限度为20字节</li>  
  39.                
  40.              <li class="l1">验证码:  
  41.                 <li class="l2" style="width: 180px;"><input name="checkImg" id="checkImg" type="text" class="input" style="width: 60px;" size="10" />  
  42.                   <img src="<%=request.getContextPath() %>/CheckImg_FT" width="49" height="22" /></li>  
  43.                
  44.             <li class="l4">  
  45.                 <label><input type="checkbox" name="flag" id="flag" value="1" <%if(flag!=null && flag.equals("1")){%> checked ; value ="1"; <%}else {%value="0" <%;}%/>记住密码</label>  
  46.                 <label><span style="margin-left:10px; color: #F00;" ><html:errors /></span></label>                 
  47.             </li>  
  48.    
  49.             <li class="l4"><input type="image" name="imageField" id="imageField" src="<%=request.getContextPath() %>/frontsite/Images/login_bnt.jpg" /></li>  
  50.         </ul>  
  51.     </div>  
  52. </form>  
  53. </div>  
  54. </body>  


2.java 类:

 


 
    1. String flag = request.getParameter("flag");  
    2. //set cookie  
    3. if(flag!=null && flag.equals("1")){  
    4.     Cookie cookie = new Cookie("cookie_user", po.getLogin_id()+"-"+form.getLogin_pwd());                  
    5.     cookie.setMaxAge(60*60*24*30); //cookie 保存30天  
    6. response.addCookie(cookie);  
    7. }else{    
    8.     Cookie cookie = new Cookie("cookie_user",po.getLogin_id()+"-"+null);                  
    9.     cookie.setMaxAge(60*60*24*30); //cookie 保存30天  
    10.     response.addCookie(cookie);               
    11. }  
posted on   Java码农220  阅读(2324)  评论(0编辑  收藏  举报
编辑推荐:
· 用 C# 插值字符串处理器写一个 sscanf
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
· .NET Core内存结构体系(Windows环境)底层原理浅谈
· C# 深度学习:对抗生成网络(GAN)训练头像生成模型
阅读排行:
· 手把手教你更优雅的享受 DeepSeek
· AI工具推荐:领先的开源 AI 代码助手——Continue
· 探秘Transformer系列之(2)---总体架构
· V-Control:一个基于 .NET MAUI 的开箱即用的UI组件库
· 乌龟冬眠箱湿度监控系统和AI辅助建议功能的实现

< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8
点击右上角即可分享
微信分享提示