java session出現(xiàn)的錯誤
更新時間:2009年07月12日 23:15:52 作者:
好郁悶哦,搞了兩個多小時,我把先把HttpSessionAttributeListener 接口的方法實現(xiàn)了
復制代碼 代碼如下:
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)
{}
}
好郁悶哦,搞了兩個多小時,我把先把HttpSessionAttributeListener 接口的方法實現(xiàn)了,但是在類的實現(xiàn)時忘記寫它了,我在Session進行添加時要是添加不進去,我找了好久,又沒錯誤,又測試了很多遍,就是添加時的監(jiān)聽沒有用,我以為我方法寫錯了,我一個字母的對了幾遍,還是沒發(fā)現(xiàn)。呵呵,在后來,我又看了前面的例子,突然之間就發(fā)現(xiàn)了,我這好像少了點什么,才加上去,一下了,好了。做程序真得細心呀。
相關(guān)文章
Hibernate識別數(shù)據(jù)庫特有字段實例詳解
這篇文章主要介紹了Hibernate識別數(shù)據(jù)庫特有字段實例詳解的相關(guān)資料,需要的朋友可以參考下2017-06-06
實例講解JSP Model2體系結(jié)構(gòu)(中)
實例講解JSP Model2體系結(jié)構(gòu)(中)...2006-10-10
servlet+JSP+mysql實現(xiàn)文件上傳的方法
這篇文章主要介紹了servlet+JSP+mysql實現(xiàn)文件上傳的方法,涉及JSP文件傳輸與判斷及數(shù)據(jù)庫操作的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-11-11

