3 Replies - 1138 Views - Last Post: 26 September 2012 - 03:18 AM

#1 qadeerhussain007  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 35
  • Joined: 05-July 12

servlet class compiling problem

Posted 21 September 2012 - 10:04 AM

hi friends i made a simple servlet class in notepad++
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class FirstServlet extends HttpServlet
{
public void doGet(HttpServletResponse response, HttpServletRequest request) throws Exception
{
PrintWriter out=response.getWriter();
out.println("hello qadeer");
}
}
but when i compiled this following error occure
javax servlet.*; dosnt exist
javax.servlet.http.*; dosnt exist

Is This A Good Question/Topic? 0
  • +

Replies To: servlet class compiling problem

#2 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1132
  • View blog
  • Posts: 2,490
  • Joined: 05-May 05

Re: servlet class compiling problem

Posted 21 September 2012 - 01:46 PM

What command are you using to compile?
Was This Post Helpful? 0
  • +
  • -

#3 DynamiteCoder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 02-June 11

Re: servlet class compiling problem

Posted 26 September 2012 - 02:50 AM

you might not have the servlet-api.jar in your project lib,.. or in the apache tomcat lib folder if you have might used this server,.. or you may not have add the jar file in your CLASSPATH environment,.
Was This Post Helpful? 1
  • +
  • -

#4 kai_itz me  Icon User is offline

  • D.I.C Head

Reputation: 28
  • View blog
  • Posts: 159
  • Joined: 03-August 12

Re: servlet class compiling problem

Posted 26 September 2012 - 03:18 AM

check for your exception ,
package hall;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HelloWorld extends HttpServlet {
  public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
      throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    out.println("Hello World");
  }
}





as DYNAMITECODER SAID THE PROBLEM IS
you might not have the servlet-api.jar in your project lib,.. or in the apache tomcat lib folder if you have might used this server,.. or you may not have add the jar file in your CLASSPATH environment,.

you have to set path to

javax servlet.*; dosnt exist
javax.servlet.http.*; dosnt exist
You need to add the path to Tomcat 6's /lib/servlet-api.jar file to the compile time classpath.

javac -cp .;/path/to/Tomcat/lib/servlet-api.jar com/example/MyServletClass.java  The classpath is where Java needs to look for imported dependencies. It will otherwise default to the current folder which is included as . in the above example. The ; is the path separator for Windows; if you're using an Unix based OS, then you need to use : instead


This post has been edited by kai_itz me: 26 September 2012 - 03:28 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1