首页 技术 正文
技术 2022年11月12日
0 收藏 370 点赞 4,081 浏览 2386 个字

1.jsp页面:

  1. <% String flag = (String)session.getAttribute(“flag”)==null?””:(String)session.getAttribute(“flag”);
  2. String name = “”;
  3. String password = “”;
  4. try{
  5. Cookie[] cookies=request.getCookies();
  6. if(cookies!=null){
  7. for(int i=0;i<cookies.length;i++){
  8. if(cookies[i].getName().equals(“cookie_user”)){
  9. String value =  cookies[i].getValue();
  10. if(value!=null&&!””.equals(value)){
  11. name=cookies[i].getValue().split(“-“)[0];
  12. if(cookies[i].getValue().split(“-“)[1]!=null && !cookies[i].getValue().split(“-“)[1].equals(“null”)){
  13. password=cookies[i].getValue().split(“-“)[1];
  14. }
  15. }
  16. }
  17. request.setAttribute(“name”,name);
  18. request.setAttribute(“passward”,password);
  19. }
  20. }
  21. }catch(Exception e){
  22. e.printStackTrace();
  23. }
  24. %>
  25. <body>
  26. <div id=”logo”><img src=”<%=request.getContextPath() %>/frontsite/Images/Logo.jpg” width=”244″ height=”44″ alt=”” /></div>
  27. <div id=”loginfrm”>
  28. <form action=”<%=request.getContextPath() %>/frontsite/login.do?method=login” method=”post” id=”forms” onsubmit=”checkForm();return false;”>
  29. <div class=”frm”>
  30. <ul>
  31. <li class=”l1″>用户名:</li>
  32. <li class=”l2″><input name=”login_id” type=”text” id=”login_id” class=”input” value=”<%=name %>”/></li>
  33. <li class=”l3″>* 最大限度为20字节</li>
  34. <li class=”l1″>密码:</li>
  35. <li class=”l2″><input name=”login_pwd” type=”password” id=”login_pwd” class=”input” value=”<%=password %>”/></li>
  36. <li class=”l3″>* 最大限度为20字节</li>
  37. <li class=”l1″>验证码:
  38. <li class=”l2″ style=”width: 180px;”><input name=”checkImg” id=”checkImg” type=”text” class=”input” style=”width: 60px;” size=”10″ />
  39. <img src=”<%=request.getContextPath() %>/CheckImg_FT” width=”49″ height=”22″ /></li>
  40. <li class=”l4″>
  41. <label><input type=”checkbox” name=”flag” id=”flag” value=”1″ <%if(flag!=null && flag.equals(“1″)){%> checked ; value =”1″; <%}else {%> value=”0” <%;}%> />记住密码</label>
  42. <label><span style=”margin-left:10px; color: #F00;” ><html:errors /></span></label>
  43. </li>
  44. <li class=”l4″><input type=”image” name=”imageField” id=”imageField” src=”<%=request.getContextPath() %>/frontsite/Images/login_bnt.jpg” /></li>
  45. </ul>
  46. </div>
  47. </form>
  48. </div>
  49. </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. }
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,907
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,432
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,247
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,058
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,690
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,728