944,129 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1589
  • Java RSS
Feb 4th, 2007
0

ServletContextAttributeListener not working

Expand Post »
Hi again, can anyone explain why the code below doesn't execute the
attributeAdded(...) method
Java Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 20
Solved Threads: 4
Junior Poster
cms271828 is offline Offline
123 posts
since Oct 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: MySql connection question.
Next Thread in Java Forum Timeline: config files in Jboss and Websphere





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC