aspose file tools*
The moose likes Servlets and the fly likes Servlet does not compile Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet does not compile" Watch "Servlet does not compile" New topic
Author

Servlet does not compile

Sukrit Sulochana
Greenhorn

Joined: Oct 13, 2005
Posts: 21
Hi,

I just wrote my first servlet. I installed the latest version of Tomcat.

When I compile the servlet I get the errors:

package javax.servlet does not exist
package javax.servlet.http does not exist

I am able to compile and run normal java programs.
What could be the problem?
Thanks,
Rajneesh
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

You need to add the servlets jar file that came with Tomcat to the classpath during the compilation. What it is named depends upon your version of Tomcat.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sukrit Sulochana
Greenhorn

Joined: Oct 13, 2005
Posts: 21
Thank you, Bear. The book I am using is old and mentions this change for an older version. I couldn't find the jar file at the path it mentioned. Can you tell me how to set it for Tomcat version 5.5?

Thanks.
Sukrit Sulochana
Greenhorn

Joined: Oct 13, 2005
Posts: 21
Ok I had set the right classpath but it wouldn't compile because I hadn't restarted the computer. Weird! After restarting it compiled.

Thanks.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

For others searching the forum:
http://faq.javaranch.com/view?CompilingServlets
[ November 04, 2005: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Originally posted by Rajneesh Joshi:
Ok I had set the right classpath but it wouldn't compile because I hadn't restarted the computer. Weird! After restarting it compiled.


Normally you would just need to close your command window and open a new one for the changes to appear.
Sukrit Sulochana
Greenhorn

Joined: Oct 13, 2005
Posts: 21
Hi David,

I didn't set the classpath using the command window but through the advanced options in the system properties window. When I set the classpath for JDK using this window, normal Java programs would not compile and I had to restart. Same thing with the servlet. That's why I said: "Weird!"

I have another problem: I wrote the servlet and its deployment descriptor (web.xml), and also the HTML page to anchor the servlet. However when I open the page http://localhost:8080/ I don't see anything. What could be the problem?

I set the ANT_HOME and TOMCAT_HOME variables already.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet does not compile