Classpath issues or bad code?

I’m trying to test out my Tomcat 7 installation using a test servlet with Java 1.6.0_24 and I’m receiving compile issues:

C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\hotdog\WEB-INF\class
es>javac HelloServlet.java
HelloServlet.java:2: package javax.servlet does not exist
import javax.servlet.;
^
HelloServlet.java:3: package javax.servlet.http does not exist
import javax.servlet.http.
;
^
HelloServlet.java:5: cannot find symbol
symbol: class HttpServlet
public class HelloServlet extends HttpServlet{
^
HelloServlet.java:6: cannot find symbol
symbol : class HttpServletResponse
location: class HelloServlet
public void doGet(HttpServletResponse request,HttpServletResponse respon
se) throws ServlectException,IOException{
^
HelloServlet.java:6: cannot find symbol
symbol : class HttpServletResponse
location: class HelloServlet
public void doGet(HttpServletResponse request,HttpServletResponse respon
se) throws ServlectException,IOException{
^
HelloServlet.java:6: cannot find symbol
symbol : class ServlectException
location: class HelloServlet
public void doGet(HttpServletResponse request,HttpServletResponse respon
se) throws ServlectException,IOException{

       ^

6 errors

My CATALINA_HOME classpath is:

.;C:\Program Files\Apache Software Foundation\Tomcat 7.0

My JAVA_HOME classpath is:

.;C:\Program Files\Java\jdk1.6.0_24

The servlet is in the following directory:

C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\hotdog\WEB-INF\classes

Finally, the actual servlet code itself is as follows:

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

public class HelloServlet extends HttpServlet{
	public void doGet(HttpServletResponse request,HttpServletResponse response) throws ServlectException,IOException{
		response.setContentType("text/html");
		PrintWriter out=response.getWriter();
		out.println("<html>");
		out.println("<head>");
		out.println("<title>Hello Servlet</title>");
		out.println("</head>");
		out.println("<body>");
		out.println("<h1>Welcome to Servlets</h1>");
		out.println("</body>");
		out.println("</html>");
	}
}

Can someone help me get this sorted out? Are the errors coming from how I’m compiling? Does it have to do with my classpath, my code, or both?

hi wolf 22!

It is your classpath…
CATALINA_HOME and JAVA_HOME are “environment variables”, I’m not really sure why you have listed multiple directories here.
when you run ‘javac’, you have the option of specifying a class path via the -cp or -classpath option.
Since you are using tomcat 7 you should compile against the servlet-api 3.0, you can get it from apache-tomcat-7.0.16/lib/servlet-api.jar, so include this in your classpath while compiling.

Jurn

Thanks, jurn. It compiled but I’m having problems getting it to show up in the browser as I’m thinking my web.xml might be off. Can you glean anything form it?:

<!DOCTYPE web-app PUBLIC
  '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN'
  'http://java.sun.com/dtd/web-app_2_3.dtd'>
<web-app>
	<servlet>
		<servlet-name>HelloServlet</servlet-name>
		<servlet-class>hotdog.HelloServlet</servlet-class>
	</servlet>

	<servlet-mapping>
		<servlet-name>HelloServlet</servlet-name>
		<url-pattern>/hotdog/*</url-pattern>
	</servlet-mapping>
</web-app>

In my browser, I’ve been trying the following URLs without any success (all of which say that the requested resources is not available):
http://localhost:8888/HelloServlet
http://localhost:8888/hotdog/HelloServlet
http://localhost:8888/webapps/hotdog/HelloServlet

None of which seem to bring up anything. Should I turn off and then turn back on Tomcat after making revisions to the XML?

I think I’m almost there… Just have a small tweak apparently.

where and how did you deploy the webapp into tomcat? (there’s a few ways to do it…)

could you also try
http://localhost:8888/hotdog/hotdog/HelloServlet

and do you see any startup logs from tomcat?

I usually reload the webapp (not necessarily tomcat) if I change the webapp’s web.xml

Jurn

Sorry, Jurn, but I had some help from our senior in the shop and figured it out (I meant to let you know earlier today that I got it fixed). What happened was that the HttpServletResponse parm inside the doGet method needed to match up with it’s data type… (I hope this makes sense because I’m still wrapping my head around it!–I got the script off some website to test my Tomcat out.)

Anyway, once we changed the “HttpServletResponse request” to “HttpServletRequest request”, everything finally panned-out. Of course, this goes without saying that this specific issue was 1 of many that our guy helped me out with, but overall, it’s working now.

Thanks again for your help, though. :slight_smile:

lol I didn’t see that typo :slight_smile:

I’m glad it is working