This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Servlets and the fly likes import javax.servlet.*; problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "import javax.servlet.*; problem" Watch "import javax.servlet.*; problem" New topic

import javax.servlet.*; problem

shu juan low

Joined: Sep 20, 2004
Posts: 3
When i compile my program in the textpad,
it show that the two of this java package
import javax.servlet.*;
import javax.servlet.http.*;
does not exist. here is the source code:
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class RequestServlet extends HttpServlet {

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
//Open input stream and read request command
ServletInputStream sis = request.getInputStream();
DataInputStream dis = new DataInputStream(sis);
String cmd = dis.readUTF();

//Open output stream
ServletOutputStream sos = response.getOutputStream();
DataOutputStream dos = new DataOutputStream(sos);


//Select action based on the request command
if (cmd.equals("getChoice"))
//read course and select action based on the course
String course = dis.readUTF();
if (course.equals("Mandarin Course"))
//write course information into output stream

else if (course.equals("Japanese Course"))
//write course information into output stream
else if (cmd.equals("addCourse"))
//read course name, date and time
String course = dis.readUTF();
String date = dis.readUTF();
String time = dis.readUTF();

// ... write course information into database here ...

//write response into output stream
dos.writeUTF("Add Course Completed");

} catch(Exception e)
//close streams

Please hep me to solve.
Thanks for help.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 32302

Welcome to JavaRanch!

Make sure the proper jar is in the classpath when you compile. You can use j2ee.jar or servlet.jar to compile and run a servlet.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12982
In Tomcat5 the file is named servlet-imp.jar in the CATALINA_HOME/common/lib directory. In Tomcat4 the name is servlet.jar.
If fiddling with CLASSPATH problems gets you down, consider using ANT to control project builds - a bit of a learning curve but you will be glad you did.
I agree. Here's the link:
subject: import javax.servlet.*; problem
It's not a secret anymore!