java webÖÐʹÓà Listener
Listener ÊÇServletµÄ¼àÌýÆ÷£¬Ëü¿ÉÒÔ¼àÌý¿Í»§¶ËµÄÇëÇó¡¢·þÎñ¶ËµÄ²Ù×÷µÈ¡£Í¨¹ý¼àÌýÆ÷£¬¿ÉÒÔ×Ô¶¯¼¤·¢Ò»Ð©²Ù×÷£¬±ÈÈç¼àÌýÔÚÏßµÄÓû§µÄÊýÁ¿¡£µ±Ôö¼ÓÒ»¸ö HttpSessionʱ£¬¾Í¼¤·¢sessionCreated(HttpSessionEvent se)·½·¨£¬ÕâÑù¾Í¿ÉÒÔ¸øÔÚÏßÈËÊý¼Ó1¡£³£ÓõļàÌý½Ó¿ÚÓÐÒÔϼ¸¸ö£º
# ServletContextAttributeListener¼àÌý¶ÔServletContextÊôÐԵIJÙ×÷£¬±ÈÈçÔö¼Ó¡¢É¾³ý¡¢ÐÞ¸ÄÊôÐÔ¡£
# ServletContextListener¼àÌýServletContext¡£µ±´´½¨ServletContextʱ£¬¼¤·¢ contextInitialized(ServletContextEvent sce)·½·¨£»µ±Ïú»ÙServletContextʱ£¬¼¤·¢contextDestroyed(ServletContextEvent sce)·½·¨¡£
# HttpSessionListener ¼àÌýHttpSessionµÄ²Ù×÷¡£µ±´´½¨Ò»¸öSessionʱ£¬¼¤·¢session Created(HttpSessionEvent se)·½·¨£»µ±Ïú»ÙÒ»¸öSessionʱ£¬¼¤·¢sessionDestroyed (HttpSessionEvent se)·½·¨¡£
# HttpSessionAttributeListener¼àÌýHttpSessionÖеÄÊôÐԵIJÙ×÷¡£µ±ÔÚSessionÔö¼ÓÒ»¸öÊôÐÔʱ£¬¼¤·¢ attributeAdded(HttpSessionBindingEvent se) ·½·¨£»µ±ÔÚSessionɾ³ýÒ»¸öÊôÐÔʱ£¬¼¤·¢attributeRemoved(HttpSessionBindingEvent se)·½·¨£»µ±ÔÚSessionÊôÐÔ±»ÖØÐÂÉèÖÃʱ£¬¼¤·¢attributeReplaced(HttpSessionBindingEvent se) ·½·¨¡£
ÏÂÃæÎÒÃÇ¿ª·¢Ò»¸ö¾ßÌåµÄÀý×Ó£¬Õâ¸ö¼àÌýÆ÷Äܹ»Í³¼ÆÔÚÏßµÄÈËÊý¡£ÔÚServletContext³õʼ»¯ºÍÏú»Ùʱ£¬ÔÚ·þÎñÆ÷¿ØÖÆ̨´òÓ¡¶ÔÓ¦µÄÐÅÏ¢¡£µ±ServletContextÀïµÄÊôÐÔÔö¼Ó¡¢¸Ä±ä¡¢É¾³ýʱ£¬ÔÚ·þÎñÆ÷¿ØÖÆ̨´òÓ¡¶ÔÓ¦µÄÐÅÏ¢¡£
Òª»ñµÃÒÔÉϵŦÄÜ£¬¼àÌýÆ÷±ØÐëʵÏÖÒÔÏÂ3¸ö½Ó¿Ú£º
# HttpSessionListener
# ServletContextListener
# ServletContextAttributeListener
ÎÒÃÇ¿´¾ßÌåµÄ´úÂ룬¼ûʾÀý14-9¡£
¡¾³ÌÐòÔ´´úÂë¡¿
1 // ==================== Program Discription =====================
2 // ³ÌÐòÃû³Æ£ºÊ¾Àý14-9 : EncodingFilter .java
3 // ³ÌÐòÄ¿µÄ£ºÑ§Ï°Ê¹ÓüàÌýÆ÷
4 // ==============================================================
5 import javax.servlet.http.*;
6 import javax.servlet.*;
7
8 public class OnLineCountListener implements HttpSessionListener,
ServletContextListener,ServletContextAttributeListener
9 {
10 private int count;
11 private ServletContext context = null;
12
13 public OnLineCountListener()
14 {
15 count=0;
16 //setContext();
17 }
18 //
Ïà¹ØÎĵµ£º
Ò»£¬ package,importÒýÈëÔÒò£º
package:
ÎÒÃǶ¼ÊìϤ³¬ÊУ¬³¬ÊÐËäÈ»ÅӴ󣬶«Î÷·±¶à£¬µ«È´¹ÜÀíµÄ¾®¾®ÓÐÌõ£¬µ±ÕÒijÑù¶«¶«Ê±£¬ÎÒÃÇÒ²ºÜÈÝÒ×ÕÒ
µ½£¬ËüµÄÒ»¸öÖØÒªµÄÔÒò¾ÍÊDzÉÓÃÁË·ÖÀà·ÅÖûúÖÆ£¬ÎïÆ··ÖÃűðÀà·ÅÖÃÔÚרÃŵÄÇøÓò£¬¼È·½±ã¹ÜÀí£¬ÓÖ·½±ãÑ°ÕÒ
PackageÒ²ÊÇÒ»¸ö·ÖÀà·ÅÖö«¶«µÄÇøÓò£¬²»¹ýËü·Åµ ......
1.À¬»øÊÕ¼¯Ëã·¨µÄºËÐÄ˼Ïë
¡¡¡¡JavaÓïÑÔ½¨Á¢ÁËÀ¬»øÊÕ¼¯»úÖÆ£¬ÓÃÒÔ¸ú×ÙÕýÔÚʹÓõĶÔÏóºÍ·¢ÏÖ²¢»ØÊÕ²»ÔÙʹÓÃ(ÒýÓÃ)µÄ¶ÔÏ󡣸ûúÖÆ¿ÉÒÔÓÐЧ·À·¶¶¯Ì¬ÄÚ´æ·ÖÅäÖпÉÄÜ·¢ÉúµÄÁ½¸öΣÏÕ£ºÒòÄÚ´æÀ¬»ø¹ý¶à¶øÒý·¢µÄÄÚ´æºÄ¾¡£¬ÒÔ¼°²»Ç¡µ±µÄÄÚ´æÊÍ·ÅËùÔì³ÉµÄÄÚ´æ·Ç·¨ÒýÓá£
¡¡¡¡À¬»øÊÕ¼¯Ëã·¨µÄºËÐÄ˼ÏëÊÇ£º¶ÔÐéÄâ»ú¿ÉÓÃÄÚ´æ¿Õ¼ä£¬¼´¶Ñ¿Õ ......
CSVÎļþ¼ò½é
¶ººÅ·Ö¸ôÐÍÈ¡Öµ¸ñʽ£¨Ó¢ÎÄÈ«³ÆΪComma Separated Values£¬¼ò³ÆCSV£©£¬ÊÇÒ»ÖÖ´¿Îı¾¸ñʽ£¬ÓÃÀ´´æ´¢Êý¾Ý¡£ÔÚCSVÖУ¬Êý¾ÝµÄ×Ö¶ÎÓɶººÅ·Ö¿ª£¬³ÌÐòͨ¹ý¶ÁÈ¡ÎļþÖØд´½¨ÕýÈ·µÄ×ֶΣ¬·½·¨ÊÇÿ´ÎÓöµ½¶ººÅʱ¿ªÊ¼ÐÂÒ»¶ÎÊý¾Ý¡£
CSVÎļþÊÇÒ»¸ö¼ÆËã»úÊý¾ÝÎļþÓÃÓÚÖ´ÐÐÉóÅкÍÕæÕýµÄ×éÖ¯¹¤¾ß£¬¶ººÅ·Ö¸ôµÄÇåµ¥¡£³£³£±»ÓÃÓÚÒÆ ......
ÏÂÊöÊ®Ëĸö¼¼ÇÉ£¬ÊÇÐí¶àÈËÔÚ´óÁ¿µÄÊý¾Ý¿â·ÖÎöÓëÉè¼Æʵ¼ùÖУ¬Öð²½×ܽá³öÀ´µÄ¡£¶ÔÓÚÕâЩ¾ÑéµÄÔËÓ㬶ÁÕß²»ÄÜÉú°ïÓ²Ì×£¬ËÀ¼ÇÓ²±³£¬¶øÒªÏû»¯Àí½â£¬ÊµÊÂÇóÊÇ£¬Áé»îÕÆÎÕ¡£²¢Öð²½×öµ½£ºÔÚÓ¦ÓÃÖз¢Õ¹£¬ÔÚ·¢Õ¹ÖÐÓ¦Óá£
1. Ôʼµ¥¾ÝÓëʵÌåÖ®¼äµÄ¹Øϵ
¿ÉÒÔÊÇÒ»¶ÔÒ»¡¢Ò»¶Ô¶à¡¢¶à¶Ô¶àµ ......
À¬»ø»ØÊÕÆ÷ÊÇÈçºÎ¹¤×÷µÄ£¿ÎÒÏÖÔھͼòµ¥µÄ½éÉÜÒ»ÏÂ
Ê×ÏÈÒªÃ÷È·¼¸µã£º
JavaÊÇÔÚ¶ÑÉÏΪ¶ÔÏó·ÖÅä¿Õ¼äµÄ
À¬»ø»ØÊÕÆ÷Ö»¸úÄÚ´æÓйأ¬Ê²Ã´IO°¡£¬ÍøÂçÁ¬½Ó°¡£¬¹ÜËüPÊÂ
µ±¿ÉÓÃÄÚ´æÊýÁ¿½ÏµÍʱ£¬Sun°æ±¾µÄÀ¬»ø»ØÊÕÆ÷²Å»á±»¼¤»î
ÔÚÀ¬»ø»ØÊÕÆ÷»ØÊÕÀ¬»ø֮ǰ£¬ÎÒÃÇÏÈÀ´Á˽âÒ»ÏÂJava·ÖÅä¶ÔÏóµÄ·½Ê½£¬JavaµÄ¶Ñ¸üÏñÒ»¸ö´«ËÍ´ø£¬Ã¿·ÖÅäÒ» ......