¹ØÓÚ¼àÌýÆ÷£¨Java£©
×é¼þ
¹¦ÄÜ
Com.guipei.listener. SessionListener
¼àÌý×é¼þ£¬Íê³ÉHttpSessionContextµÄ¹¦ÄÜ
index.jsp
ʵÏÖÓû§µÇ½£¬´´½¨ÐµÄsession
logout.jsp
ʵÏÖÓû§Í˳ö£¬Óû§×Ô¶¯É¾³ýsession
display.jsp
ÏÔʾÓû§µÇ½ÐÅÏ¢£¬ÔÚÓû§µÇ½ºó×Ô¶¯×ªÈë
session.jsp
Áгöµ±Ç°ËùÓеÄsession
kill.jsp
ɱµôÖ¸¶¨µÄ»á»°£¬Ê¹Õâ¸öÓû§Á¬½ÓÎÞЧ
¼àÌýÀàcom.guipei.listener.SessionListener ʵÏÖweb applicationµÄ¼àÌý¹¦ÄÜ£¬ËüʵÏÖÁËHttpSessionListener½Ó¿Ú£¬¿ÉÒÔ¼àÌýsessionCreated(HttpSessionEvent se)ºÍsessionDestroyed(HttpSessionEvent se) ·½·¨£¬Òò´ËÎÒÃÇ¿ÉÒÔºÜÈÝÒ×µÄÔÚsessionµÄ´´½¨ºÍÏú»Ùʼþ¹ý³ÌÖд¦ÀísessionµÄ¿ØÖÆ¡£
ÔÚ´ËÀàÖУ¬ÎÒÃÇ´´½¨Ò»¸ö¾²Ì¬ÊµÀý±äÁ¿Hashtable ht£¬²ÉÓÃHashtableµÄÒ»¸öºÃ´¦ÊÇËüÊÇḬ̈߳²È«µÄ¼¯ºÏÀ࣬ÎÞÐëÎÒÃÇÔÙ¶à×öÏ̴߳¦Àí¡£²ÉÓÃÕâ¸öcollectionÀà±£´æÎÒÃÇËùÒª¿ØÖƵÄsession¶ÔÏó¡£ÔÚ¼àÌýʼþÖÐÈÝÒ׵Ĵ¦ÀíÏà¹ØÈÎÎñ¡£
²Î¿´È«²¿´úÂ룺
package com.guipei.listener;
import java.util.Hashtable;
import java.util.Iterator;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
public class SessionListener implements HttpSessionListener {
// ¼¯ºÏ¶ÔÏ󣬱£´æsession ¶ÔÏóµÄÒýÓÃ
static Hashtable ht = new Hashtable();
// ʵÏÖHttpSessionListener½Ó¿Ú£¬Íê³Ésession´´½¨Ê¼þ¿ØÖÆ
public void sessionCreated(HttpSessionEvent arg0) {
HttpSession session = arg0.getSession();
ht.put(session.getId(), session );
System.out.println("create session :" + session.getId() );
}
// ʵÏÖHttpSessionListener½Ó¿Ú£¬Íê³ÉsessionÏú»Ùʼþ¿ØÖÆ
public void sessionDestroyed(HttpSessionEvent arg0) {
HttpSession session = arg0.getSession();
System.out.println("destory session :" + session.getId() );
Ïà¹ØÎĵµ£º
1 »ù±¾½éÉÜ
¿ÉÒÔ˵CSV¸ñʽµÄÎļþ¾³£Åöµ½£¬ºÎΪCSV¸ñʽ£¬CVSÈ«³Æcomma-separated values£¬¾ÍÊǵäÐ͵ÄÓöººÅ¸ô¿ªµÄÎļþ£¬±ÈÈçÏÂÃæÕâÖÖÎļþ¸ñʽ
Name,company
zhangsan,ibm
lisi,oracle
ÕâÖÖ¾ÍÊǵäÐ͵ÄCSV¸ñʽÎļþ¡£²»¹ýÒ²¿ÉÒÔÀ©Õ¹µ½ÆäËü·ûºÅ¸ô¿ªµÄ×Ö·û£¬±ÈÈç
Name#company
Zhangsan#ibm ......
¡¡¡¡ÄÇôҪ³ÉΪ¼Ü¹¹Ê¦µÄ;¾¶ËƺõÖ»ÓÐÏÖÔÚ½ÏΪÁ÷ÐеÄÈí¼þѧԺºÍ¸öÈË×ÔÎÒÅàÑøÁË¡£¹ØÓÚÈí¼þѧԺÎÒ½Ó´¥¹ý²»ÉÙ£¬Æä×ÚÖ¼¾ø´ó²¿·Ö¶¼ÊÇÔì¾Í(or´òÔì)ÆóÒµ ÐèÒªµÄÈí¼þ¼Ü¹¹Ê¦(or³ÌÐòÔ±orÈ˲Å)¡£½ÌʦÀ´Ô´ÓëÆóÒµ¡¢Ñ§Ô±À´Ô´ÓëÆóÒµ¡¢È˲ÅÊäË͵½ÆóÒµÊÇËûÃÇ°ìѧµÄÊֶΡ£¾¡¹Ü¸÷¸öÈçÓêºó´ºËñ°ã³öÏÖµÄÈí¼þѧԺ¿ÚºÅ²î ²»¶à£¬µ«¿ÖÅ´ó¶àÖ»ÊÇΪÁËȦ ......
1. J2EEÊǹ淶£¬ÊÇÒ»ÖÖJSR±ê×¼£¬ÓÐÏêϸÎĵµ£¬²ûÊöJ2EEÌṩÄÄЩ¹¦ÄÜ£¬¿ÉÒÔÏÂÔØÕâÑùÎĵµ£¬µ±È»»¹ÓÐһЩ´úÂë½Ó¿Ú£¬ÕâÊǵäÐÍJavaÊÀ½çÖеĿò¼Ü´úÂë+±ê×¼ÎĵµÐÎʽ£¬ÕâÊÇÖ»ÓÐ×ÔÓÉÊÀ½ç²ÅÓеĹ淶£¬ÔÚ΢ÈíMSÊÀ½çÄãÊǾø¶Ô²»»á¿´µ½µÄ£¬ËùÒÔ£¬´Ó΢Èíת¹ýÀ´µÄ£¬»áÔΣ¬»á²»ÊÊÓ¦£¬²»ÄÜÔÙ°´ÕÕËûÃÇÒÔÇ°µÄ¾ÑéÀ´¿´´ý×ÔÓɵÄÐÂÊÀ½ç¡£
2.¼Ü¹¹ÊǾ ......