Problem compiling a simple java file

Hi,

When I try to compile the following simple java file

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class HowdyServlet extends HttpServlet {

public void doGet(HttpServletRequest request,

HttpServletResponse response)

throws IOException, ServletException {

PrintWriter out = response.getWriter();

response.setContentType("text/html");

out.println("<html>");

out.println("<body>");

out.println("<center><h1>Hi</h1></center>");

out.println("</body>");

out.println("</html>");

}

}

at the command prompt as follows

C:\Shared\CBT\Java 2 JSP and Java Servlets\03\servlet1>javac -classpath

"C:\Program Files\Java\j2re1.4.2_03\lib\ext\QTJava.zip" *.java

Or

C:\Shared\CBT\Java 2 JSP and Java Servlets\03\servlet1>javac *.java

Or

C:\Shared\CBT\Java 2 JSP and Java Servlets\03\servlet1>javac HowdyServlet.java

I get the following errors and I cannot compile this java file -

HowdyServlet.java:2: package javax.servlet does not exist

import javax.servlet.*;

^

HowdyServlet.java:3: package javax.servlet.http does not exist

import javax.servlet.http.*;

^

HowdyServlet.java:5: cannot find symbol

symbol: class HttpServlet

public class HowdyServlet extends HttpServlet {

^

HowdyServlet.java:6: cannot find symbol

symbol : class HttpServletRequest

location: class HowdyServlet

public void doGet(HttpServletRequest request,

^

HowdyServlet.java:7: cannot find symbol

symbol : class HttpServletResponse

location: class HowdyServlet

HttpServletResponse response)

^

HowdyServlet.java:8: cannot find symbol

symbol : class ServletException

location: class HowdyServlet

throws IOException, ServletException {

^

6 errors

I have installed the latest JEE 5 SDK on Win XP Home. I have the following variable set as follows,

CLASSPATH = .;C:\Program Files\Java\j2re1.4.2_03\lib\ext\QTJava.zip

PATH = C:\Sun\AppServer\jdk\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;C:\Program Files\QuickTime\QTSystem;C:\Sun\AppServer\lib\ant\bin

ANT_HOME = C:\Sun\AppServer\lib\ant

I have spent hours scratching my head but don抰 have a clue. I was wondering if you have any idea as why I might be getting these errors.

Thank you for your time.

Green

[2632 byte] By [green2006a] at [2007-10-3 3:11:09]
# 1
code tags: http://forum.java.sun.com/help.jspa?sec=formattingdo you have the jee stuff installed? you need to add it to your classpath.
mlka at 2007-7-14 21:01:59 > top of Java-index,Java Essentials,New To Java...
# 2

Yes I have installed JEE 5 and my variable including Classpath are set as follows,

CLASSPATH = .;C:\Program Files\Java\j2re1.4.2_03\lib\ext\QTJava.zip

PATH = C:\Sun\AppServer\jdk\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;C:\Program Files\QuickTime\QTSystem;C:\Sun\AppServer\lib\ant\bin

ANT_HOME = C:\Sun\AppServer\lib\ant

I am new to Java and so I am confused with this language. Is my CLASSPATH not correct?

green2006a at 2007-7-14 21:01:59 > top of Java-index,Java Essentials,New To Java...
# 3
Not it is not, you don't have any of the packages for JEE in your class path.> I am new to Java and so I am confused with this language.Ignore JEE then until you understand the basics of the language.
mlka at 2007-7-14 21:01:59 > top of Java-index,Java Essentials,New To Java...
# 4
So how do I add packages to my classpath? Do I need to download and Install something? What do I need to add to my classpath?thanks
green2006a at 2007-7-14 21:01:59 > top of Java-index,Java Essentials,New To Java...
# 5

> So how do I add packages to my classpath? Do I need

> to download and Install something? What do I need to

> add to my classpath?

Check the docs that came with the JEE install.

> I am new to Java and so I am confused with this language.

Ignore JEE then until you understand the basics of the language.

mlka at 2007-7-14 21:01:59 > top of Java-index,Java Essentials,New To Java...
# 6
Didn't you read my posting in which I said I tried to find solution. I did try to find it in the documentation that came with JEE but didn't get any clue as of yet and that's why I am asking for help.
green2006a at 2007-7-14 21:01:59 > top of Java-index,Java Essentials,New To Java...
# 7

> Didn't you read my posting in which I said I tried to

> find solution. I did try to find it in the

> documentation that came with JEE but didn't get any

> clue as of yet and that's why I am asking for help.

He probably did read your post, but he suggested that you don't attempt to work on any JEE things until you've learned and grasped the basics of JSE. JEE adds an addtional layer of complexity to the base complexity that Java already has so you'll have a very, very hard time using it or developing with it, unless you are good with the basics. I tend to agree with that notion.

JoachimSauera at 2007-7-14 21:01:59 > top of Java-index,Java Essentials,New To Java...
# 8

Hello, did you read the answers?

You have to put j2ee.jar or servlet-api.jar in your classpath. Those JAR files are included in the Java EE package somewhere. Remove the QTJava.zip junk from the classpath.

If you don't know what the classpath is and how to set it, read this:

[url=http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/classpath.html]Setting the class path[/url]

[url=http://java.sun.com/j2se/1.3/docs/tooldocs/findingclasses.html]How Classes are Found[/url]

And I'll repeat what the others say: if you are very new to Java, then Java EE will probably be way over your head. First learn the language and the standard API. If you understand that well, start with Java EE. Or do you already know what servlets are, and that you need a servlet container to run them, and how to deploy them etc.?

jesperdja at 2007-7-14 21:01:59 > top of Java-index,Java Essentials,New To Java...
# 9
hi here the problem is u don't have javax package, first u have to get servlet.jar file this contains javax lib files and set the class path for that. This might be one of the solution.try to do this.
lee4lenina at 2007-7-14 21:01:59 > top of Java-index,Java Essentials,New To Java...
# 10
I added path to j2ee.jar in my classpath variable and eveything worked fine.
green2006a at 2007-7-14 21:01:59 > top of Java-index,Java Essentials,New To Java...