Java Session Error _JSP programming

Source: Internet
Author: User
Copy Code code as follows:

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 ("Initialize * * * *");
}
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)
{}
}


Good depressed oh, two hours, I put the first Httpsessionattributelistener interface to achieve the method, but in the implementation of the class forgot to write it, I add in the session if not to add, I looked for a long time, and no mistakes, and tested many times, is to add when the monitor is not used, I think I wrote the wrong way, I have a letter of several times, or did not find. Oh, in the later, I looked at the previous example, suddenly found, I this seems to be a little something, just add to, a moment, OK. It's really careful to do the procedure.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.