Cookie操作以及如何在js中调用jsp变量
生活随笔
收集整理的這篇文章主要介紹了
Cookie操作以及如何在js中调用jsp变量
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
存Cookie
Cookie idCookie = new Cookie("userId", request.getParameter("id"));Cookie psdCookie = new Cookie("psd", request.getParameter("psd"));
idCookie.setMaxAge(3600);//存3600秒也就是1小時(shí)
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 中調(diào)用 jsp 變量
<script language="javascript">document.loginform.id.value = '<%=user_id == null ? "" : user_id%>';
document.loginform.psd.value = '<%=psd == null ? "" : psd%>';
</script>
轉(zhuǎn)載于:https://www.cnblogs.com/lihuiyy/archive/2011/10/20/2219439.html
總結(jié)
以上是生活随笔為你收集整理的Cookie操作以及如何在js中调用jsp变量的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 张宏江:工程水平决定创新能力(转载于百度
- 下一篇: Python 新浪微博 各种表情使用频率