• Cookie操作以及如何在js中调用jsp变量


    存Cookie

    Cookie idCookie = new Cookie("userId", request.getParameter("id"));
    Cookie psdCookie = new Cookie("psd", request.getParameter("psd"));
    idCookie.setMaxAge(3600);//存3600秒也就是1小时
    psdCookie.setMaxAge(3600);
    response.addCookie(idCookie);
    response.addCookie(psdCookie);

    取Cookie

          Cookie cookies[] = request.getCookies();
    if(cookies != null){
    System.out.println("**********" + cookies.length);
    for(int i = 0; i < cookies.length; i++){
    if(cookies[i].getName().equals("userId")){
    user_id = cookies[i].getValue();
    }else{
    if(cookies[i].getName().equals("psd")){
    psd = cookies[i].getValue();
    }
    }
    if(user_id != null && psd != null){
    break;
    }
    }

    在 js 中调用 jsp 变量

      <script language="javascript">
    document.loginform.id.value = '<%=user_id == null ? "" : user_id%>';
    document.loginform.psd.value = '<%=psd == null ? "" : psd%>';
    </script>






  • 相关阅读:
    bean的作用域和生命周期
    装配Bean的三种方式
    BeanFactory和ApplicationContext对比
    创建 Spring容器的三种方式
    约束
    三大范式
    事务
    EdgeRank
    TCP三次握手四次挥手
    Linux权限解释
  • 原文地址:https://www.cnblogs.com/lihuiyy/p/2219439.html
Copyright © 2020-2023  润新知