File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes cannot import servlet apis Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "cannot import servlet apis" Watch "cannot import servlet apis" New topic
Author

cannot import servlet apis

Ken Teoh
Greenhorn

Joined: Jul 20, 2006
Posts: 18
Hi,

I'm getting these errors when compiling a servlet

src/com/example/web/BeerSelect.java:3: package javax.servlet does not exist
import javax.servlet.*;
^
src/com/example/web/BeerSelect.java:4: package javax.servlet.http does not exist

import javax.servlet.http.*;
^
src/com/example/web/BeerSelect.java:7: cannot find symbol
symbol: class HttpServlet
public class BeerSelect extends HttpServlet {
^
src/com/example/web/BeerSelect.java:9: cannot find symbol
symbol : class HttpServletRequest
location: class com.example.web.BeerSelect
public void doPost(HttpServletRequest request,
^
src/com/example/web/BeerSelect.java:10: cannot find symbol
symbol : class HttpServletResponse
location: class com.example.web.BeerSelect

HttpServletResponse response)

^
src/com/example/web/BeerSelect.java:11: cannot find symbol
symbol : class ServletException
location: class com.example.web.BeerSelect

throws IOException, ServletException {

^
I understand you need to add a jar file but where should I add it and where is it located?

My command was

javac -classpath /common/lib/servlet-api.jar:classes:. -d classes src/com/example/web/BeerSelect.java
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Is the /common folder really at the root of your file system?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ken Teoh
Greenhorn

Joined: Jul 20, 2006
Posts: 18
Hi thanks I realize my mistake and change the classpath to

javac -classpath C:/Documents and Settings/Keng/tomcat/common/lib/servlet-api.jar:classes:. -d classes src/com/example/web/BeerSelect.java

however, its giving me an invalid flag error
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

At this point it's becoming clear that this is not a Servlets issue but an issue with learning how to use the javac command line.

As such this has been moved to the Java in General (beginner) forum where such issues are discussed.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Originally posted by Ken Teoh:

however, its giving me an invalid flag error


It's generally a good idea to show the exact wording of the error message.

It may be that on Windows you need to use ";" as the classpath separator character, but I'm not sure if that is the issue (I never compile from the command line, I use Ant).

This type of issue is a common question in this forum. Searching for previous discussions may prove useful.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19072
    
  40

The classpath delimiter for Windows is different from Unix. Unix uses the ":" character as you have in the example. Windows uses the ";" character.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cannot import servlet apis