java session出現(xiàn)的錯(cuò)誤
更新時(shí)間:2009年07月12日 23:15:52 作者:
好郁悶哦,搞了兩個(gè)多小時(shí),我把先把HttpSessionAttributeListener 接口的方法實(shí)現(xiàn)了
復(fù)制代碼 代碼如下:
package cn.lang.any.listener;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class AmpList implements
ServletContextListener,HttpSessionListener,HttpSessionAttributeListener
{
private ServletContext application=null;
public void contextInitialized(ServletContextEvent sce)
{
this.application=sce.getServletContext();
this.application.setAttribute("alluser",new ArrayList());
//System.out.println("初始化****");
}
public void sessionCreated(HttpSessionEvent se)
{
//System.out.println("session ****");
}
public void sessionDestroyed(HttpSessionEvent se)
{
List l=(List)this.application.getAttribute("alluser");
String value=(String)se.getSession().getAttribute("uname");
l.remove(value);
this.application.setAttribute("alluser",l);
}
public void attributeAdded(HttpSessionBindingEvent se)
{
//System.out.println("Hello");
List lis=(List)this.application.getAttribute("alluser");
lis.add(se.getValue());
this.application.setAttribute("alluser",lis);
}
public void attributeRemoved(HttpSessionBindingEvent se)
{
}
public void attributeReplaced(HttpSessionBindingEvent se)
{
}
public void contextDestroyed(ServletContextEvent sce)
{}
}
好郁悶哦,搞了兩個(gè)多小時(shí),我把先把HttpSessionAttributeListener 接口的方法實(shí)現(xiàn)了,但是在類的實(shí)現(xiàn)時(shí)忘記寫它了,我在Session進(jìn)行添加時(shí)要是添加不進(jìn)去,我找了好久,又沒(méi)錯(cuò)誤,又測(cè)試了很多遍,就是添加時(shí)的監(jiān)聽(tīng)沒(méi)有用,我以為我方法寫錯(cuò)了,我一個(gè)字母的對(duì)了幾遍,還是沒(méi)發(fā)現(xiàn)。呵呵,在后來(lái),我又看了前面的例子,突然之間就發(fā)現(xiàn)了,我這好像少了點(diǎn)什么,才加上去,一下了,好了。做程序真得細(xì)心呀。
相關(guān)文章
JSP 多條SQL語(yǔ)句同時(shí)執(zhí)行的方法
這是一段基本的SQL插入語(yǔ)句,分別將兩個(gè)值插入到兩個(gè)表中,上面的程序已經(jīng)能夠完成這一需求,但是實(shí)際操作中并不建議這樣寫2009-02-02Struts html:checkbox框初始默認(rèn)是選中的解決方法
在使用struts標(biāo)簽html:checkbox 的時(shí)候,如何讓checkbox框默認(rèn)是選中的,本文提供解決方法,需要了解的朋友可以參考下2012-12-12JSP實(shí)用教程之簡(jiǎn)易頁(yè)面編輯器的實(shí)現(xiàn)方法(附源碼)
對(duì)于一些剛?cè)腴T的程序員來(lái)說(shuō),在一些實(shí)際的開(kāi)發(fā)中可能會(huì)用到編輯器,那么如何在JSP頁(yè)面中嵌入并使用編輯器,下面這篇文章就給大家介紹了JSP簡(jiǎn)易頁(yè)面編輯器的實(shí)現(xiàn)方法,文中介紹的非常詳細(xì),需要的朋友可以參考下。2017-07-07jsp頁(yè)面調(diào)用applet實(shí)現(xiàn)人民幣的大小寫轉(zhuǎn)換
jsp頁(yè)面調(diào)用applet實(shí)現(xiàn)人民幣的大小寫轉(zhuǎn)換...2006-10-10jsp和servlet中實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn)的方式實(shí)例總結(jié)
這篇文章主要介紹了jsp和servlet中實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn)的方式,結(jié)合實(shí)例形式較為詳細(xì)的總結(jié)分析了jsp和servlet中實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn)的常用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10Apache+Servlet+Jsp環(huán)境設(shè)置(中)
Apache+Servlet+Jsp環(huán)境設(shè)置(中)...2006-10-10