This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet does not compile

 
Sukrit Sulochana
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sukrit Sulochana
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For others searching the forum:
http://faq.javaranch.com/view?CompilingServlets
[ November 04, 2005: Message edited by: Ben Souther ]
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic