📄 1007402.xml
字号:
<?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 论坛助手 Ver 1.0 B0402提供下载。 改进了很多,功能完备!
★  浏览帖子速度极快![建议系统使用ie5.5以上]。 ★  多种帖子实现界面。 
★  保存帖子到本地[html格式]★  监视您关注帖子的回复更新。
★  可以直接发贴、回复帖子★  采用XML接口,可以一次性显示4页帖子,同时支持自定义每次显示帖子数量。可以浏览历史记录! 
★  支持在线检测程序升级情况,可及时获得程序更新的信息。
★★ 签名  ●  
     可以在您的每个帖子的后面自动加上一个自己设计的签名哟。
Http://www.ChinaOK.net/csdn/csdn.zip
Http://www.ChinaOK.net/csdn/csdn.rar
Http://www.ChinaOK.net/csdn/csdn.exe    [自解压]
</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><%
  String action = (String)request.getParameter("action") ;
  if ( action != null && action.equals("userlogin") ) 
  {
      String timeZone  = (String)request.getParameter("timeZone") ;
      String userName  = (String)request.getParameter("userName") ;
      Cookie cookie2=new Cookie("USERNAME", userName);
      Cookie cookie3=new Cookie("TIMEZONE", timeZone);
      cookie2.setMaxAge(365*24*60*60);
      cookie3.setMaxAge(365*24*60*60);
      response.addCookie(cookie2);
      response.addCookie(cookie3);
      Connection conn = MyDB.getConnection();
      session.setAttribute("THE_PARTNERNO","11");
	  session.setAttribute("THE_TIMEZONE",timeZone);
	  
	  int  partnerNo = 11 ;
	  session.setAttribute("THE_FUNCAREA","COMPANY");	  
      String password = (String)request.getParameter("userPassword");
	  String sql = "select u.user_no,p.password  from users u,user_passwd p where u.loginName='"+MyDB.toSQLStr(userName)+"' and u.partner_no="+ partnerNo+
	         " and p.user_no=u.user_no" ;
      String[][] data = MyDB.fetchStrData(conn,sql) ;
      if ( data ==null || !data[0][1].equals(password) )
      {
           out.println("<script>alert('用户不存在或者口令不对');parent.document.form0.userName.focus();</script>");
           return;
      }
      int userNo = Integer.parseInt(data[0][0]) ;
      String helpedName = (String)request.getParameter("helpedName");
      if (helpedName != null && helpedName.trim().length() != 0 ) 
      {
          sql = "select user_no from users where loginName='"+MyDB.toSQLStr(helpedName)+"' and partner_no='"+ partnerNo+"'" ;
		  data = MyDB.fetchStrData(conn, sql );
          if( data == null)
          {
              out.println("<script>alert('该被帮助者不存在');parent.document.form0.helpedName.focus();</script>");
              return;
          }
          int helpedNo = Integer.parseInt(data[0][0]) ;
          sql = "select func_no from helper_right where user_no="+helpedNo +" and helpedby="+userNo +" and expireDate >= getDate()" ;
          data = MyDB.fetchStrData(conn,sql );
          if ( data == null  )
          {
            out.println("<script>alert('你无权帮助"+helpedName+"');parent.document.form0.helpedName.focus();</script>");
            return;
          }
          session.setAttribute("THE_USERNO",""+helpedNo );               
          session.setAttribute("THE_HELPEDBY",""+userNo);    
	  }
	  else
      {
         sql = "select func_no from rights where user_no="+userNo  ;
       	 data = MyDB.fetchStrData(conn,sql );
	     if ( data == null )
	     {
          //  out.println("<script>alert('你无权访问系统');parent.document.form0.userName.focus();</script>");
          //  return;
         }
         session.setAttribute("THE_USERNO",""+userNo ); 
         session.setAttribute("THE_HELPEDBY",null);    
      }
      
	  if ( data == null )  session.setAttribute("THE_RIGHTS",null );     
      else
	  {
		  int rows = data.length;
          int[] rights = new int[rows];
          for(int i = 0 ;i < rows ; ++ i)
          {
             rights[i] = Integer.parseInt(data[i][0]);
    	  }
	      session.setAttribute("THE_RIGHTS",rights);     
      }
      String uri = "/netoffice/main.jsp" ;
      out.println("<script>parent.document.form0.action.value='';parent.location='" + uri+"';</script>");
	  return ;
   }
   java.util.GregorianCalendar toDay = new java.util.GregorianCalendar();
   int sYEAR  = toDay.get(toDay.YEAR);
   int sMonth = toDay.get(toDay.MONTH)+1; 
   int sDay = toDay.get(toDay.DATE); 
   int hour = toDay.get(toDay.HOUR); 
   int MINUTE = toDay.get(toDay.MINUTE);
   int AM_PM = toDay.get(toDay.AM_PM);
   if (AM_PM >=1) hour = hour + 12;  
   String today = sYEAR+"年"+sMonth+"月"+sDay+"日"+hour+"时"+MINUTE+"分"; 
   String userName="",timeZone="8" ;
   Cookie cookies[]=request.getCookies();
   int j = (cookies==null )?0:cookies.length ;
   for ( int i = 0 ; i < j ;i++ )
   {
     if ( cookies[i].getName().equals("USERNAME") ) 
        userName = cookies[i].getValue();
     else if ( cookies[i].getName().equals("TIMEZONE") ) 
        timeZone = cookies[i].getValue();
   }
   String[][] data={
          {"12","(GMT+12)马绍尔群岛"},
          {"11","(GMT+11)马加丹"},
          {"10","(GMT+10)悉尼,墨尔本"},
          {"9","(GMT+09)东京,汉城"},
          {"8","(GMT+08)北京,新加坡"},
          {"7","(GMT+07)曼谷,雅加达"},
          {"6","(GMT+06)仰光"},
          {"5","(GMT+05)伊斯兰堡"},
          {"4","(GMT+04)喀布尔"},
          {"3","(GMT+03)莫斯科,科威特"},
          {"2","(GMT+02)雅典,开罗"},
          {"1","(GMT+01)巴黎,罗马"},
          {"0","(GMT+00)伦敦,爱丁堡"},
          {"-1","(GMT-01)亚速尔群岛"},
          {"-2","(GMT-02)中大西洋"},
          {"-3","(GMT-03)格陵兰"},
          {"-4","(GMT-04)加拿大"},
          {"-5","(GMT-05)印第安纳(东)"},
          {"-6","(GMT-06)中美洲,墨西哥"},
          {"-7","(GMT-07)亚利桑那"},
          {"-8","(GMT-08)蒂华纳"},
          {"-9","(GMT-09)阿拉斯加"},
          {"-10","(GMT-10)夏威夷"},
          {"-11","(GMT-11)中途岛"}} ;
    String timeZoneSelect = MySession.toOptions(data,timeZone);
%></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 + -