ServletContextAttributeListener not working

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2006
Posts: 101
Reputation: cms271828 is an unknown quantity at this point 
Solved Threads: 4
cms271828 cms271828 is offline Offline
Junior Poster

ServletContextAttributeListener not working

 
0
  #1
Feb 4th, 2007
Hi again, can anyone explain why the code below doesn't execute the
attributeAdded(...) method
  1. package pack1;
  2.  
  3. import java.io.*;
  4. import java.net.*;
  5.  
  6. import javax.servlet.*;
  7. import javax.servlet.http.*;
  8.  
  9.  
  10.  
  11. public class ShowFrame extends HttpServlet implements ServletContextAttributeListener
  12. {
  13. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  14. throws ServletException, IOException
  15. {
  16. this.getServletContext().setAttribute("name","cat");
  17. String v=(String)this.getServletContext().getAttribute("name");
  18. response.setContentType("text/html;charset=UTF-8");
  19. PrintWriter out = response.getWriter();
  20. // TODO output your page here
  21. out.println("<html>");
  22. out.println("<head>");
  23. out.println("<title>Servlet ShowFrame</title>");
  24. out.println("</head>");
  25. out.println("<body>");
  26. out.println("<h1>V = "+v+"</h1>");
  27. out.println("</body>");
  28. out.println("</html>");
  29.  
  30. out.close();
  31. }
  32.  
  33. public void attributeAdded(ServletContextAttributeEvent scab)
  34. {
  35. this.getServletContext().setAttribute("name","chicken");
  36. }
  37.  
  38. public void attributeRemoved(ServletContextAttributeEvent scab)
  39. {
  40. this.getServletContext().setAttribute("name","chicken");
  41. }
  42.  
  43. public void attributeReplaced(ServletContextAttributeEvent scab)
  44. {
  45. this.getServletContext().setAttribute("name","chicken");
  46. }
  47. }
The servlet is included in the web.xml file under <listener> tag, and I'm using Netbeans 5.0.

Thanks for any help
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC