Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

import javax.servlet.*; problem

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
mport java.io.*;
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
response.setContentType("text/plain");
ServletOutputStream sos = response.getOutputStream();
DataOutputStream dos = new DataOutputStream(sos);


try{

//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
dos.writeUTF("20/12/04");
dos.writeUTF("8:00am");
dos.flush();

}
else if (course.equals("Japanese Course"))
{
//write course information into output stream
dos.writeUTF("22/12/04");
dos.writeUTF("8:00am");
dos.flush();
}
}
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");
dos.flush();
}

} catch(Exception e)
{
e.printStackTrace();
}
finally
{
//close streams
dis.close();
dos.close();
}


}
}
Please hep me to solve.
Thanks for help.
 
author & internet detective
Posts: 39986
806
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Bill
 
Blood pressure normal? What do I change to get "magnificent"? Maybe this tiny ad?
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic