Java session errors

Source: Internet
Author: User

Copy codeThe Code is 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)
{}
}


So depressing. After more than two hours, I first implemented the HttpSessionAttributeListener interface method, but I forgot to write it when implementing the class, when I add a Session, if I do not add it, I have been searching for a long time, no errors, and I have tested it many times, that is, the added listener is useless. I thought my method was wrong, I got a letter right several times, but I still didn't find it. Well, later I saw the previous example and suddenly I found out that I was missing something before I added it. Be very careful with the program.

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.