954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

ServletContextAttributeListener not working

Hi again, can anyone explain why the code below doesn't execute the
attributeAdded(...) method

package pack1;
 
import java.io.*;
import java.net.*;
 
import javax.servlet.*;
import javax.servlet.http.*;
 


public class ShowFrame extends HttpServlet implements ServletContextAttributeListener
{
       protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    {
        this.getServletContext().setAttribute("name","cat");
        String v=(String)this.getServletContext().getAttribute("name");
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        // TODO output your page here
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet ShowFrame</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>V = "+v+"</h1>");
        out.println("</body>");
        out.println("</html>");
         
        out.close();
    }
 
    public void attributeAdded(ServletContextAttributeEvent scab)
    {
        this.getServletContext().setAttribute("name","chicken");
    }
 
    public void attributeRemoved(ServletContextAttributeEvent scab)
    {
        this.getServletContext().setAttribute("name","chicken");
    }
 
    public void attributeReplaced(ServletContextAttributeEvent scab)
    {
        this.getServletContext().setAttribute("name","chicken");
    }
}

The servlet is included in the web.xml file under tag, and I'm using Netbeans 5.0.

Thanks for any help

cms271828
Junior Poster
123 posts since Oct 2006
Reputation Points: 20
Solved Threads: 4
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You