-1

I am a new JAVA learner and i am compling java files into class files with CMD. Yesterday i started with JAVA Servlet. But CMD giving me error.

servlet.java:2: error: package javax.servlet does not exist import javax.servlet.http.*;

Then i searched google and every topic saying - set you CLASSPATTH.

Enviornment variables --> Path --> edit

C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\servlet-api.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\jsp-api.jar;

Done. But again CMD giving me same error.

Code -

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

public class helloworld extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws IOException {

        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.print("Hello World from GET method ");

    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws IOException {

        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.print("Hello World from POST method ");

    }
}

javac servlet.java again same error

MatthiasG
  • 4,434
  • 3
  • 27
  • 47
  • Path != classpath... You could have done a bit of research, and found [this post](http://stackoverflow.com/questions/2096283/including-jars-in-classpath-on-commandline-javac-or-apt). Oops, it seems I have to write some more text as you wanted reply not to be in one line, so be it... – ppeterka Jan 24 '13 at 08:42
  • How are you executing it? This should be accessed from an URL correctly mapped in your web.xml – Eugenio Cuevas Jan 24 '13 at 08:42
  • @Eugenio he's far from that, stuck at compiling... – ppeterka Jan 24 '13 at 08:43
  • import javax.servlet.http.; // this won't compile – PeterMmm Jan 24 '13 at 08:43
  • @PeterMmm frankly, I didn't even see the dot until you pointed out... However, the error message indicates that there was actually an asterisk after the dot, at least i nthe version he tried to compile... – ppeterka Jan 24 '13 at 08:47
  • possible duplicate of [Compiling servlets with javac](http://stackoverflow.com/questions/5791446/compiling-servlets-with-javac) – McDowell Jan 24 '13 at 08:54
  • For you as newbie: it's Java and **not** JAVA! – Michael-O Jan 24 '13 at 09:18
  • I also tried. -cp [libraries] [other options] [file(s) to compile] But no luck – Lovepreet Singh Batth Jan 24 '13 at 09:39

1 Answers1

0

set those libraries into the compiler classpath using java -cp [libraries] [other options] [file(s) to compile]

jwenting
  • 5,505
  • 2
  • 25
  • 30