| Author |
Unable to import
|
Ankitt Gupta
Ranch Hand
Joined: Feb 19, 2009
Posts: 101
|
|
Hi all
I am unable to import the javax.servlet.http.*;
please help
|
 |
Vijitha Kumara
Bartender
Joined: Mar 24, 2008
Posts: 3670
|
|
|
What are you trying to do? Unable to compile a servlet? If so, you need servlet-api.jar in your classpath. Tell us what you are trying to accomplish and how you are doing it. Then we can help easily.
|
SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
|
 |
Ankitt Gupta
Ranch Hand
Joined: Feb 19, 2009
Posts: 101
|
|
i am doing the beerV1 project from the head first.
i included the class path but it saying the package javax.servlet.http.*; does not exist
|
 |
Vijitha Kumara
Bartender
Joined: Mar 24, 2008
Posts: 3670
|
|
|
When do you get this error? Show us the stack trace. Have you setup the classpath ? If so how? Try "echo %CLASSPATH%" (on Windows) from command prompt and post the output.
|
 |
Ankitt Gupta
Ranch Hand
Joined: Feb 19, 2009
Posts: 101
|
|
Vijitha Kumara wrote:When do you get this error? Show us the stack trace. Have you setup the classpath ? If so how? Try "echo %CLASSPATH%" (on Windows) from command prompt and post the output.
the class path is ok.it is compile time error in which it is unable to find the package
|
 |
Ankitt Gupta
Ranch Hand
Joined: Feb 19, 2009
Posts: 101
|
|
this is the class path
.;C:\Program Files\Java\jre1.6.0_04\lib\ext\QTJava.zip
|
 |
Vijitha Kumara
Bartender
Joined: Mar 24, 2008
Posts: 3670
|
|
it is compile time error in which it is unable to find the package
That's because the required jar files (servlet-api.jar in this case) not found in the classpath.
|
 |
Vijitha Kumara
Bartender
Joined: Mar 24, 2008
Posts: 3670
|
|
Anky Gupta wrote:this is the class path
.;C:\Program Files\Java\jre1.6.0_04\lib\ext\QTJava.zip
There is the problem. You have to add an entry to refer the servlet API implementation in the classpath which can be found among your container's library files (probably inside "YOURCONTAINERHOME/lib"). BTW, which container you are using?
|
 |
Ankitt Gupta
Ranch Hand
Joined: Feb 19, 2009
Posts: 101
|
|
D:\Prog\MyProject\beerV1>javac -classpath \C:\ProgramFiles\Apache\Tomcat\common\
lib\servlet-api.jar;classes:. -d classes src\com\example\web\BeerSelect.java
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 req, HttpServletResponse res) throws IOExce
ption, ServletException
^
src\com\example\web\BeerSelect.java:9: cannot find symbol
symbol : class HttpServletResponse
location: class com.example.web.BeerSelect
public void doPost( HttpServletRequest req, HttpServletResponse res) throws IOExce
ption, ServletException
^
src\com\example\web\BeerSelect.java:9: cannot find symbol
symbol : class ServletException
location: class com.example.web.BeerSelect
public void doPost( HttpServletRequest req, HttpServletResponse res) throws IOExce
ption, ServletException
^
6 errors
This the command prompt
|
 |
Vijitha Kumara
Bartender
Joined: Mar 24, 2008
Posts: 3670
|
|
Anky, Check my previous reply. You will be fine after adding the servlet API jar file to your classpath
|
 |
Ankitt Gupta
Ranch Hand
Joined: Feb 19, 2009
Posts: 101
|
|
.;C:\Program Files\Java\jre1.6.0_04\lib\ext\QTJava.zip;C:\Program Files\Apache\Tomcat\common\lib
IS this class path okay?
|
 |
Vijitha Kumara
Bartender
Joined: Mar 24, 2008
Posts: 3670
|
|
Anky Gupta wrote:.;C:\Program Files\Java\jre1.6.0_04\lib\ext\QTJava.zip;C:\Program Files\Apache\Tomcat\common\lib
IS this class path okay?
Almost. Just make it,
C:\Program Files\Apache\Tomcat\common\lib\servlet-api.jar
|
 |
Ankitt Gupta
Ranch Hand
Joined: Feb 19, 2009
Posts: 101
|
|
.;C:\Program Files\Java\jre1.6.0_04\lib\ext\QTJava.zip;C:\Program Files\Apache\Tomcat\common\lib\servlet-api.jar
I have set this as class path in the Environment Variable but still no avail
|
 |
Vijitha Kumara
Bartender
Joined: Mar 24, 2008
Posts: 3670
|
|
Just type,
javac -d classes src\com\example\web\BeerSelect.java
If you got any error post it here.
|
 |
Ankitt Gupta
Ranch Hand
Joined: Feb 19, 2009
Posts: 101
|
|
Yippe finally compiled
Much appreciated Thanks.
Thank you for having patience with me.
you are such a nice person
Cheers
|
 |
Vijitha Kumara
Bartender
Joined: Mar 24, 2008
Posts: 3670
|
|
No problem
|
 |
 |
|
|
subject: Unable to import
|
|
|