• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Failed to register listener in web.xml

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a Tiger class implemented HttpSessionAttributeListener, then I register it in the web.xml.

As soon as I put the following code in the web.xml, I get
"SEVER: Context [/myWeb] startup failed due to previous errors" from TomCat console

--- web.xml --
<listener>
<listener-class>coreservlets.listeners.Tiger</listener-class>
</listener>
--

If I remove above code in web.xml, I don't see error message, so i am sure it's above code causing error, but I don't know what's wrong. Below is my Tiger class.

Can anybody help me?

Thanks in advance!!!

-- ---- ---
package coreservlets.listeners;
import javax.servlet.http.*;
public class Tiger implements HttpSessionAttributeListener
{
private String breed;
public Tiger(String breed) { this.breed = breed; }
public String getBreed() {return breed; }

public void attributeAdded (HttpSessionBindingEvent se )
{
System.out.println("a session attribute has been added.");
System.out.println(se.getSession().getId());
System.out.println(se.getName() + "', '" + se.getValue());
}
public void attributeRemoved(HttpSessionBindingEvent se )
{
System.out.println("a session attribute has been removed.");
}
public void attributeReplaced(HttpSessionBindingEvent se )
{
System.out.println("a session attribute has been replaced.");
}
}
--------------------


-- TigerAttributeListenerTester servlet--
package coreservlets.listeners;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class TigerAttributeListenerTester extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("Test HttpSessionAttributeListener <br>");
HttpSession session = request.getSession(true);
Tiger tiger = new Tiger("ohhh tiger.");
session.setAttribute("tigerTiger", tiger );
}
}
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your Tiger class has no default constructor (the one without paramaters), so the container will fail to make a new instance.

By looking at your code, I'm wondering if you wanted to use HttpSessionBindingListener instead.
 
Tiffiny Yang
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Satou !!! Your help is much appreciated !!

You're right, it needs a non-arg constructor.


Tiffiny
 
reply
    Bookmark Topic Watch Topic
  • New Topic