• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cannot import servlet apis

 
Ken Teoh
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64720
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the /common folder really at the root of your file system?
 
Ken Teoh
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64720
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64720
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21022
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The classpath delimiter for Windows is different from Unix. Unix uses the ":" character as you have in the example. Windows uses the ";" character.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic