views:

125

answers:

2

I have installed Tomcat 5.5 in windows vista home basic. I have set classpath to "C:\program files\apache software foundation\tomcat 5.5\common\lib\servlet-api.jar". now there are two problems. 1. I could not compile my servlets. It says package javax.servlet.* dosenot exist. 2. I could not connect with local host in chrome nor in explorer.

these errors are appearing inspite of server instance running. Classpath to java sdk and tomcat are different. is it the matter of concern. Please help. I have invested considerable amount of time figuring out the problem. thanx in advance.

+1  A: 

I have set classpath to "C:\program files\apache software foundation\tomcat 5.5\common\lib\servlet-api.jar"

If this means CLASSPATH environment variable, you're learning a valuable lesson: it's worthless. javac.exe and java.exe ignore it; so do all Java EE app servers like Tomcat; so do all IDEs like IntelliJ.

You'll have to add servlet-api.jar to your CLASSPATH using javac.exe -cp every time you compile in a command shell, or add it to your IDE project CLASSPATH, or set it up in Ant.

If you can't connect to localhost using Chrome or Explorer, it probably means that you haven't packaged or deployed your app properly. Make sure you create a valid WAR file and put it in the Tomcat 5.x /webapps directory to deploy.

duffymo
It's by the way only ignored when you use any the `-cp`, `-classpath` or `-jar` arguments. If you don't use any of them, the `%CLASSPATH%` will be used. It's however indeed a poor practice.
BalusC
A: 

I could not compile my servlets. It says package javax.servlet.* dosenot exist.

It means that the classpath for javac is not been correctly specified. It should go like so:

javac -cp .;"/path with spaces/to/servlet-api.jar" com/example/YourServlet.class

Note that you need to surround a path with spaces by doublequotes.

I could not connect with local host in chrome nor in explorer. These errors are appearing inspite of server instance running.

Then you used the wrong domain/port. When running Tomcat at the local machine, the domain should at least be localhost. The actual port can be determined in Tomcat/conf/server.xml file. It defaults to 8080, but can be changed during the Windows setup wizard. The final URL should look like http://localhost:8080. If you use port 80 which is the default HTTP port, then the :80 part can be omitted from the URL.

Classpath to java sdk and tomcat are different.

The %CLASSPATH% environment variable is worthless. Use -cp argument. If you want to avoid long typing/remembering everytime, consider using a .bat file with the command, or a build tool like Ant, or an IDE like Eclipse.

The %JAVA_HOME% environment variable is however important. Tomcat needs to know it in order to have access to the toolset to compile JSP files. The %JAVA_HOME% should point to the installation directory of the JDK.

BalusC
now its that i can connect with tomcat 5.5 but still cant compile my servlet with same error reporting every time.i have tried to compile it from both location where my working java directory as well as keeping servlet in tomcat 5.5 folder.and second thing is tomcat asked for jre path which i located as "c:\program files\java\jre6".and in tomcat 5.5 configuration it says jvm location as"C:\Program Files\Java\jre6\bin\client\jvm.dll"also pls tell if tomcat needs jre or jdk
Nitesh