• 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

about error code

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ERROR INFORMATION
ListenerTester.java:3: package com.example does not exist
import com.example.*;
^
ListenerTester.java:15: cannot access Dog
bad class file: .\Dog.class
class file contains wrong class: com.example.Dog
Please remove or make sure it appears in the correct subdirectory of the classpa
th.
Dog dog = (Dog) getServletContext().getAttribute("dog");
^
2 errors

C:\apache-tomcat-5.5.16\webapps\beer-v1\WEB-INF\classes\com\example>javac Listen
erTester.java
ListenerTester.java:15: cannot access Dog
bad class file: .\Dog.class
class file contains wrong class: com.example.Dog
Please remove or make sure it appears in the correct subdirectory of the classpa
th.
Dog dog = (Dog) getServletContext().getAttribute("dog");
^
1 error

Please help me !!! The following is source file.


package com.example;
import javax.servlet.*;


public class MyServletContextListener implements ServletContextListener
{
public void contextInitialized(ServletContextEvent event)
{
ServletContext sc=event.getServletContext();
String dogBreed=sc.getServletContext("breed");
Dog d=new Dog(dogBreed);
sc.setAttribute("dog",d);
}


public void contextDestroyed(ServletContextEvent event)
{
}
}





package com.example;


public class Dog
{
private String breed;

public Dog(String breed)
{
this.breed;
}

public String getBreed()
{
return breed;
}
}




package com.example;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;


public class ListenerTester extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("test context attributes set by listener<br>");
out.println("<br>");
Dog dog=(Dog) getServletContext().getAttribute("dog");
out.println("Dog's breed is: " + dog.getBreed());
}
}




web.xml


<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com.xml/ns/j2ee/web-app_2_4.xsd"
version="2.4"

<servlet>
<servlet-name>ListenerTester</servlet-class>
<servlet-class>com.example.ListenerTester</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>ListenerTester</servlet-name>
<url-pattern>/ListenerTest.do</url-pattern>
</servlet-mapping>

<context-param>
<param-name>breed</param-name>
<param-value>Great Dane</param-value>
</context-param>

<listener>
<listener-class>
com.example.MyServletContextListener
</listener-class>
</listener>
</web-app>
[ June 02, 2006: Message edited by: owen huan ]
 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see no question. You will usually get a faster and more detailed response if you post an actual question.
Anyway,

ListenerTester.java:15: cannot access Dog
bad class file: .\Dog.class
class file contains wrong class: com.example.Dog
Please remove or make sure it appears in the correct subdirectory of the classpa
th.


Seems pretty clear, your Dog is not sitting where/how it is supposed to be in relation to your source when you compile. And/or you do not have your classpath set accordingly for the Dog.
[ June 02, 2006: Message edited by: Ed Ward ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic