Member Avatar for nssltd

Hi sorry about this kind of nooby question but i have started learning java and i am making a Chat Application, i am making it using the killer game programming in java book. But i have ran into a problem.

The Code asks me to import

import javax.servlet.*;
      import javax.servlet.http.*;

but according to my IDE netbeans 6.9

Package javax.servlet.*; does not exist.
Package javax.servlet.http.*; does not exist.

These imports play a huge part in the project as you need the servlets for parts such as these

public class ChatServlet extends HttpServlet 
{
   private ChatGroup cg;   // for storing client information

   public void init() throws ServletException
   {  cg = new ChatGroup();  }


   public void doGet( HttpServletRequest request,
                      HttpServletResponse response )
      throws ServletException, IOException
   // look at the cmd parameter to decide which message the client sent
   {
     String command = request.getParameter("cmd");
     System.out.println("Command: " + command);

     if (command.equals("hi"))
       processHi(request, response);
     else if (command.equals("bye"))
       processBye(request, response);
     else if (command.equals("who"))
       processWho(response);
     else if (command.equals("msg"))
       processMsg(request, response);
     else if (command.equals("read"))
       processRead(request, response);
     else
       System.out.println("Did not understand command: " + command);
   }  // end of doGet()



  private void processHi(HttpServletRequest request,
                         HttpServletResponse response)
    throws IOException
  /* Message format: ChatServlet?cmd=hi&name=??  
       
     The client wants to join the chat group. 
     The server returns a uid cookie, or rejects the client.
  */
  {
    int uid = -1;  // default for failure
    String userName = request.getParameter("name");

    if (userName != null)
      uid = cg.addUser(userName);  // attempt to add to group

    if (uid != -1) {  // the request has been accepted
      Cookie c = new Cookie("uid", ""+uid);
      response.addCookie(c);
    }
      
    PrintWriter output = response.getWriter();
    if (uid != -1)
      output.println("ok");
    else
      output.println("no");  // request was rejected
    output.close();
  }  // end of processHi()

If you wanted i would put the full code of the .java file down, just ask on the post.

Thanks in advance

NSSLTD

You need to install the "Java Web and EE" components in Netbeans, or the Java EE SDK

Member Avatar for nssltd

Ok i thought i already had it, but i will install the java web from your link thanks for it!

Member Avatar for nssltd

Hi well thanks that didn't seem to work for some reason... so instead i found a zip file containing all the javax.servlet classes aswell as the javax.http classes. I have downloaded them from the internet from here but i have no idea how to use these classes i was just wondering if anyone could help me use these class files in my netbeans ide ?

You can add references to the jar files in the Libraries section of your Project Properties. You can get to them by right-clicking the project in the browswer or through the File menu.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.