您现在的位置是:网站首页> 编程资料编程资料
java session出现的错误_JSP编程_
2023-05-25
379人已围观
简介 java session出现的错误_JSP编程_
复制代码 代码如下:
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 接口的方法实现了,但是在类的实现时忘记写它了,我在Session进行添加时要是添加不进去,我找了好久,又没错误,又测试了很多遍,就是添加时的监听没有用,我以为我方法写错了,我一个字母的对了几遍,还是没发现。呵呵,在后来,我又看了前面的例子,突然之间就发现了,我这好像少了点什么,才加上去,一下了,好了。做程序真得细心呀。
您可能感兴趣的文章:
相关内容
- JSP XMLHttpRequest动态无刷新及其中文乱码处理_JSP编程_
- Java 通过设置Referer反盗链_JSP编程_
- JSP 点击链接后下载文件(相当于右键另存)功能_JSP编程_
- J2ME/J2EE实现用户登录交互 实现代码_JSP编程_
- 在Jsp Servlet中页面重新定向总汇_JSP编程_
- jsp 重复提交问题_JSP编程_
- jdk与jre的区别 很形象,很清晰,通俗易懂_JSP编程_
- Java 项目生成静态页面的代码_JSP编程_
- jsp 对request.getSession(false)的理解(附程序员常疏忽的一个漏洞)_JSP编程_
- java Struts2 在拦截器里的跳转问题_JSP编程_
