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{
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.
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>
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.