aspose file tools*
The moose likes Servlets and the fly likes about error code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "about error code " Watch "about error code " New topic
Author

about error code

owen huan
Greenhorn

Joined: Jun 02, 2006
Posts: 1
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 ]
Ed Ward
Ranch Hand

Joined: Jan 30, 2006
Posts: 147
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: about error code