小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

徹底搞定JSP在線人數(shù)

 sowill 2005-12-11
文件名為onLineUser.java 

歡迎訪問(wèn)javajia家(http://www.),由yuking制作。2001.1.1 
*/ 

import javax.servlet.http.*;  
import javax.servlet.*;  
import java.util.*;  

public class onLineUser implements HttpSessionBindingListener {  
 public onLineUser(){}  

 private Vector users=new Vector(); 

 public int getCount(){ 
   users.trimToSize(); 
   return users.capacity(); 
 } 
 public boolean existUser(String userName){ 
  users.trimToSize(); 
  boolean existUser=false; 
  for (int i=0;i<users.capacity();i++ ) { 
    if (userName.equals((String)users.get(i))){ 
     existUser=true; 
     break; 
    } 
  } 
  return existUser; 
 } 

 public boolean deleteUser(String userName) { 
  users.trimToSize(); 
  if(existUser(userName)){ 
    int currUserIndex=-1; 
    for(int i=0;i<users.capacity();i++){ 
     if(userName.equals((String)users.get(i))){ 
         currUserIndex=i; 
         break; 
     } 
    } 
   if (currUserIndex!=-1){ 
    users.remove(currUserIndex); 
    users.trimToSize(); 
    return true; 
   } 
  } 
  return false; 
 } 

 public Vector getOnLineUser(){ 
  return users; 
 } 

 public void valueBound(HttpSessionBindingEvent e) {  
      users.trimToSize(); 
      if(!existUser(e.getName())){ 
             users.add(e.getName()); 
             System.out.print(e.getName()+"\t  登入到系統(tǒng)\t"+(new Date())); 
             System.out.println("     在線用戶數(shù)為:"+getCount()); 
      }else 
             System.out.println(e.getName()+"已經(jīng)存在"); 
     }  

 public void valueUnbound(HttpSessionBindingEvent e) {  
           users.trimToSize(); 
           String userName=e.getName(); 
           deleteUser(userName); 
           System.out.print(userName+"\t  退出系統(tǒng)\t"+(new Date())); 
           System.out.println("     在線用戶數(shù)為:"+getCount()); 
    }  
}  

///////////////////////////////////////////////////////////////////////////// 
<% 
/**這是顯示在線用戶的jsp文件 

文件名為onLineUser.jsp 

歡迎訪問(wèn)javajia家(http://www.),由yuking制作。2001.1.1 
*/ 
%> 
<%@ page contentType="text/html;charset=gb2312" %>  
<%@ page import="onLineUser,java.util.*" %>  
<jsp:useBean id="onlineuser" class="onLineUser" scope="application"/> 
<html>  
<head>  
<title>搞定JSP在線人數(shù)</title> 
</head> 
<body>  
<center>  
  <p><h1>登陸成功,歡迎您訪問(wèn)Java家!</h1></p> 
</center> 
<%  session = request.getSession(false); %>  
<%  
 String username=request.getParameter("username"); 
 if (onlineuser.existUser(username)){ 
   out.println("用戶<font color=red>"+username+"</font>已經(jīng)登陸!"); 
 }else{ 
   session.setMaxInactiveInterval(50); //Sesion有效時(shí)長(zhǎng),以秒為單位 
   session.setAttribute(username,onlineuser);  
   out.println("歡迎新用戶:<font color=red>"+username+"</font>登陸到系統(tǒng)!"); 
 } 
 out.println("<br>當(dāng)前在線用戶人數(shù):<font color=red>"+onlineuser.getCount()+"</font><br>"); 
 Vector vt=onlineuser.getOnLineUser(); 
 Enumeration e = vt.elements(); 
 out.println("在線用戶列表"); 
 out.println("<table border=1>"); 
 out.println("<tr><td>用戶名</td></tr>"); 
    while(e.hasMoreElements()){ 
          out.println("<tr><td>"); 
          out.println((String)e.nextElement()+"<br>"); 
          out.println("</td></tr>"); 
    } 
 out.println("</table>"); 
     
%>  
<center>  
  <p>yuking制作</p> 
  <p> </p> 
<% 
 out.println("<p><a href=‘logout.jsp?username="+username+"‘>退出系統(tǒng)</a></p>"); 
%> 
</center>  
</body>  
</html>  

//////////////////////////////////////////////////////////////////////////////////// 
<% 
/**這是用戶退出的jsp文件 

文件名為logout.jsp 

歡迎訪問(wèn)javajia家(http://www.),由yuking制作。2001.1.1 
*/ 
%> 
<%@ page contentType="text/html;charset=gb2312" %>  
<%@ page import="onLineUser,java.util.*" %>  
<jsp:useBean id="onlineuser" class="onLineUser" scope="application"/> 
<html>  
<head>  
<title>搞定JSP在線人數(shù)</title> 
</head> 
<body>  
<center>  
  <p><h1>登陸成功,歡迎您訪問(wèn)Java家!</h1></p> 
</center> 
<%  
 String username=request.getParameter("username"); 
 if(onlineuser.deleteUser(username)) 
   out.println(username+"已經(jīng)退出系統(tǒng)!"); 
 else 
   out.println(username+"沒(méi)有登陸到系統(tǒng)!"); 
%>  
<center>  
  <p>yuking制作</p> 
  <p> </p> 
  <p><a href="logout.jsp">退出系統(tǒng)</a></p> 
</center>  
</body>  
</html>  

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多