⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1007402.xml

📁 论坛精华帖子
💻 XML
📖 第 1 页 / 共 2 页
字号:
<?xml version='1.0' encoding='GB2312'?>
<?xml-stylesheet type='text/xsl' href='../csdn.xsl'?>
<Topic>
<Issue>
<PostUserNickName>冰风</PostUserNickName>
<rank>一级(初级)</rank>
<ranknum>user1</ranknum>
<credit>100</credit>
<TopicId>1007402</TopicId>
<TopicName>关于cookie和session的使用!</TopicName>
<PostUserId>261682</PostUserId>
<PostUserName>fightplane</PostUserName>
<RoomName>JSP</RoomName>
<ReplyNum>8</ReplyNum>
<PostDateTime>2002-9-9 9:21:45</PostDateTime>
<Point>100</Point>
<ReadNum>0</ReadNum>
<RoomId>28</RoomId>
<EndState>2</EndState>
<Content>我使用session做用户登陆,发现过一段时间不用页面。session就会失效。
cookie我用不好。希望贴一个能够使用的cookie登陆的例子。

================================================================

CSDN&#32;论坛助手&#32;Ver&#32;1.0&#32;B0402提供下载。&#32;改进了很多,功能完备!

★&#32;&#32;浏览帖子速度极快![建议系统使用ie5.5以上]。&#32;★&#32;&#32;多种帖子实现界面。&#32;
★&#32;&#32;保存帖子到本地[html格式]★&#32;&#32;监视您关注帖子的回复更新。
★&#32;&#32;可以直接发贴、回复帖子★&#32;&#32;采用XML接口,可以一次性显示4页帖子,同时支持自定义每次显示帖子数量。可以浏览历史记录!&#32;
★&#32;&#32;支持在线检测程序升级情况,可及时获得程序更新的信息。

★★&#32;签名&#32;&#32;●&#32;&#32;
&#32;&#32;&#32;&#32;&#32;可以在您的每个帖子的后面自动加上一个自己设计的签名哟。

Http://www.ChinaOK.net/csdn/csdn.zip
Http://www.ChinaOK.net/csdn/csdn.rar
Http://www.ChinaOK.net/csdn/csdn.exe&#32;&#32;&#32;&#32;[自解压]

</Content>
</Issue>
<Replys>
<Reply>
<PostUserNickName>)虚竹和尚(</PostUserNickName>
<rank>两星(中级)</rank>
<ranknum>star2</ranknum>
<credit>100</credit>
<ReplyID>6491530</ReplyID>
<TopicID>1007402</TopicID>
<PostUserId>62467</PostUserId>
<PostUserName>xycleo</PostUserName>
<Point>60</Point>
<Content>&lt;%
&#32;&#32;String&#32;action&#32;=&#32;(String)request.getParameter("action")&#32;;
&#32;&#32;if&#32;(&#32;action&#32;!=&#32;null&#32;&amp;&amp;&#32;action.equals("userlogin")&#32;)&#32;
&#32;&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;String&#32;timeZone&#32;&#32;=&#32;(String)request.getParameter("timeZone")&#32;;
&#32;&#32;&#32;&#32;&#32;&#32;String&#32;userName&#32;&#32;=&#32;(String)request.getParameter("userName")&#32;;

&#32;&#32;&#32;&#32;&#32;&#32;Cookie&#32;cookie2=new&#32;Cookie("USERNAME",&#32;userName);
&#32;&#32;&#32;&#32;&#32;&#32;Cookie&#32;cookie3=new&#32;Cookie("TIMEZONE",&#32;timeZone);
&#32;&#32;&#32;&#32;&#32;&#32;cookie2.setMaxAge(365*24*60*60);
&#32;&#32;&#32;&#32;&#32;&#32;cookie3.setMaxAge(365*24*60*60);
&#32;&#32;&#32;&#32;&#32;&#32;response.addCookie(cookie2);
&#32;&#32;&#32;&#32;&#32;&#32;response.addCookie(cookie3);

&#32;&#32;&#32;&#32;&#32;&#32;Connection&#32;conn&#32;=&#32;MyDB.getConnection();
&#32;&#32;&#32;&#32;&#32;&#32;session.setAttribute("THE_PARTNERNO","11");
&#9;&#32;&#32;session.setAttribute("THE_TIMEZONE",timeZone);
&#9;&#32;&#32;
&#9;&#32;&#32;int&#32;&#32;partnerNo&#32;=&#32;11&#32;;
&#9;&#32;&#32;session.setAttribute("THE_FUNCAREA","COMPANY");&#9;&#32;&#32;
&#32;&#32;&#32;&#32;&#32;&#32;String&#32;password&#32;=&#32;(String)request.getParameter("userPassword");

&#9;&#32;&#32;String&#32;sql&#32;=&#32;"select&#32;u.user_no,p.password&#32;&#32;from&#32;users&#32;u,user_passwd&#32;p&#32;where&#32;u.loginName='"+MyDB.toSQLStr(userName)+"'&#32;and&#32;u.partner_no="+&#32;partnerNo+
&#9;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;"&#32;and&#32;p.user_no=u.user_no"&#32;;
&#32;&#32;&#32;&#32;&#32;&#32;String[][]&#32;data&#32;=&#32;MyDB.fetchStrData(conn,sql)&#32;;
&#32;&#32;&#32;&#32;&#32;&#32;if&#32;(&#32;data&#32;==null&#32;||&#32;!data[0][1].equals(password)&#32;)
&#32;&#32;&#32;&#32;&#32;&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;out.println("&lt;script&gt;alert('用户不存在或者口令不对');parent.document.form0.userName.focus();&lt;/script&gt;");
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;return;
&#32;&#32;&#32;&#32;&#32;&#32;}
&#32;&#32;&#32;&#32;&#32;&#32;int&#32;userNo&#32;=&#32;Integer.parseInt(data[0][0])&#32;;

&#32;&#32;&#32;&#32;&#32;&#32;String&#32;helpedName&#32;=&#32;(String)request.getParameter("helpedName");
&#32;&#32;&#32;&#32;&#32;&#32;if&#32;(helpedName&#32;!=&#32;null&#32;&amp;&amp;&#32;helpedName.trim().length()&#32;!=&#32;0&#32;)&#32;
&#32;&#32;&#32;&#32;&#32;&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;sql&#32;=&#32;"select&#32;user_no&#32;from&#32;users&#32;where&#32;loginName='"+MyDB.toSQLStr(helpedName)+"'&#32;and&#32;partner_no='"+&#32;partnerNo+"'"&#32;;
&#9;&#9;&#32;&#32;data&#32;=&#32;MyDB.fetchStrData(conn,&#32;sql&#32;);
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;if(&#32;data&#32;==&#32;null)
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;out.println("&lt;script&gt;alert('该被帮助者不存在');parent.document.form0.helpedName.focus();&lt;/script&gt;");
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;return;
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;}
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;int&#32;helpedNo&#32;=&#32;Integer.parseInt(data[0][0])&#32;;
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;sql&#32;=&#32;"select&#32;func_no&#32;from&#32;helper_right&#32;where&#32;user_no="+helpedNo&#32;+"&#32;and&#32;helpedby="+userNo&#32;+"&#32;and&#32;expireDate&#32;&gt;=&#32;getDate()"&#32;;
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;data&#32;=&#32;MyDB.fetchStrData(conn,sql&#32;);
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;if&#32;(&#32;data&#32;==&#32;null&#32;&#32;)
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;out.println("&lt;script&gt;alert('你无权帮助"+helpedName+"');parent.document.form0.helpedName.focus();&lt;/script&gt;");
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;return;
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;}
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;session.setAttribute("THE_USERNO",""+helpedNo&#32;);&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;session.setAttribute("THE_HELPEDBY",""+userNo);&#32;&#32;&#32;&#32;
&#9;&#32;&#32;}
&#9;&#32;&#32;else
&#32;&#32;&#32;&#32;&#32;&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;sql&#32;=&#32;"select&#32;func_no&#32;from&#32;rights&#32;where&#32;user_no="+userNo&#32;&#32;;
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#9;&#32;data&#32;=&#32;MyDB.fetchStrData(conn,sql&#32;);
&#9;&#32;&#32;&#32;&#32;&#32;if&#32;(&#32;data&#32;==&#32;null&#32;)
&#9;&#32;&#32;&#32;&#32;&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;//&#32;&#32;out.println("&lt;script&gt;alert('你无权访问系统');parent.document.form0.userName.focus();&lt;/script&gt;");
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;//&#32;&#32;return;
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;}
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;session.setAttribute("THE_USERNO",""+userNo&#32;);&#32;
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;session.setAttribute("THE_HELPEDBY",null);&#32;&#32;&#32;&#32;
&#32;&#32;&#32;&#32;&#32;&#32;}
&#32;&#32;&#32;&#32;&#32;&#32;
&#9;&#32;&#32;if&#32;(&#32;data&#32;==&#32;null&#32;)&#32;&#32;session.setAttribute("THE_RIGHTS",null&#32;);&#32;&#32;&#32;&#32;&#32;
&#32;&#32;&#32;&#32;&#32;&#32;else
&#9;&#32;&#32;{
&#9;&#9;&#32;&#32;int&#32;rows&#32;=&#32;data.length;
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;int[]&#32;rights&#32;=&#32;new&#32;int[rows];
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;for(int&#32;i&#32;=&#32;0&#32;;i&#32;&lt;&#32;rows&#32;;&#32;++&#32;i)
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;rights[i]&#32;=&#32;Integer.parseInt(data[i][0]);
&#32;&#32;&#32;&#32;&#9;&#32;&#32;}
&#9;&#32;&#32;&#32;&#32;&#32;&#32;session.setAttribute("THE_RIGHTS",rights);&#32;&#32;&#32;&#32;&#32;
&#32;&#32;&#32;&#32;&#32;&#32;}

&#32;&#32;&#32;&#32;&#32;&#32;String&#32;uri&#32;=&#32;"/netoffice/main.jsp"&#32;;
&#32;&#32;&#32;&#32;&#32;&#32;out.println("&lt;script&gt;parent.document.form0.action.value='';parent.location='"&#32;+&#32;uri+"';&lt;/script&gt;");
&#9;&#32;&#32;return&#32;;
&#32;&#32;&#32;}


&#32;&#32;&#32;java.util.GregorianCalendar&#32;toDay&#32;=&#32;new&#32;java.util.GregorianCalendar();
&#32;&#32;&#32;int&#32;sYEAR&#32;&#32;=&#32;toDay.get(toDay.YEAR);
&#32;&#32;&#32;int&#32;sMonth&#32;=&#32;toDay.get(toDay.MONTH)+1;&#32;
&#32;&#32;&#32;int&#32;sDay&#32;=&#32;toDay.get(toDay.DATE);&#32;
&#32;&#32;&#32;int&#32;hour&#32;=&#32;toDay.get(toDay.HOUR);&#32;
&#32;&#32;&#32;int&#32;MINUTE&#32;=&#32;toDay.get(toDay.MINUTE);
&#32;&#32;&#32;int&#32;AM_PM&#32;=&#32;toDay.get(toDay.AM_PM);
&#32;&#32;&#32;if&#32;(AM_PM&#32;&gt;=1)&#32;hour&#32;=&#32;hour&#32;+&#32;12;&#32;&#32;
&#32;&#32;&#32;String&#32;today&#32;=&#32;sYEAR+"年"+sMonth+"月"+sDay+"日"+hour+"时"+MINUTE+"分";&#32;

&#32;&#32;&#32;String&#32;userName="",timeZone="8"&#32;;
&#32;&#32;&#32;Cookie&#32;cookies[]=request.getCookies();
&#32;&#32;&#32;int&#32;j&#32;=&#32;(cookies==null&#32;)?0:cookies.length&#32;;
&#32;&#32;&#32;for&#32;(&#32;int&#32;i&#32;=&#32;0&#32;;&#32;i&#32;&lt;&#32;j&#32;;i++&#32;)
&#32;&#32;&#32;{
&#32;&#32;&#32;&#32;&#32;if&#32;(&#32;cookies[i].getName().equals("USERNAME")&#32;)&#32;
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;userName&#32;=&#32;cookies[i].getValue();
&#32;&#32;&#32;&#32;&#32;else&#32;if&#32;(&#32;cookies[i].getName().equals("TIMEZONE")&#32;)&#32;
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;timeZone&#32;=&#32;cookies[i].getValue();
&#32;&#32;&#32;}

&#32;&#32;&#32;String[][]&#32;data={
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;{"12","(GMT+12)马绍尔群岛"},
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;{"11","(GMT+11)马加丹"},
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;{"10","(GMT+10)悉尼,墨尔本"},
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;{"9","(GMT+09)东京,汉城"},
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;{"8","(GMT+08)北京,新加坡"},
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;{"7","(GMT+07)曼谷,雅加达"},
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;{"6","(GMT+06)仰光"},
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;{"5","(GMT+05)伊斯兰堡"},
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;{"4","(GMT+04)喀布尔"},
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;{"3","(GMT+03)莫斯科,科威特"},
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;{"2","(GMT+02)雅典,开罗"},
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;{"1","(GMT+01)巴黎,罗马"},
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;{"0","(GMT+00)伦敦,爱丁堡"},
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;{"-1","(GMT-01)亚速尔群岛"},
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;{"-2","(GMT-02)中大西洋"},
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;{"-3","(GMT-03)格陵兰"},
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;{"-4","(GMT-04)加拿大"},
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;{"-5","(GMT-05)印第安纳(东)"},
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;{"-6","(GMT-06)中美洲,墨西哥"},
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;{"-7","(GMT-07)亚利桑那"},
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;{"-8","(GMT-08)蒂华纳"},
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;{"-9","(GMT-09)阿拉斯加"},
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;{"-10","(GMT-10)夏威夷"},
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;{"-11","(GMT-11)中途岛"}}&#32;;
&#32;&#32;&#32;&#32;String&#32;timeZoneSelect&#32;=&#32;MySession.toOptions(data,timeZone);
%&gt;</Content>
<PostDateTime>2002-9-9 9:33:37</PostDateTime>
</Reply>
<Reply>
<PostUserNickName>砸死我</PostUserNickName>
<rank>四级(中级)</rank>
<ranknum>user4</ranknum>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -