Can't compile my first servlet program

hi guys,
there are some problems with compiling the first servlet program(helloservlet).
the error is following
C:\SERVLET-CODE\hello1>javac HelloServlet.java
HelloServlet.java:4: package javax.servlet does not exist
import javax.servlet.*;
^
HelloServlet.java:5: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
HelloServlet.java:15: cannot resolve symbol
symbol : class HttpServlet
location: class HelloServlet
public class HelloServlet extends HttpServlet {
^
HelloServlet.java:16: cannot resolve symbol
symbol : class HttpServletRequest
location: class HelloServlet
public void doGet(HttpServletRequest request,
^
HelloServlet.java:17: cannot resolve symbol
symbol : class HttpServletResponse
location: class HelloServlet
HttpServletResponse response)
^
HelloServlet.java:18: cannot resolve symbol
symbol : class ServletException
location: class HelloServlet
throws ServletException, IOException {
^
6 errors
i don't know why it can not find the import java.*
and i already set up the classpath
and my code is
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/** Simple servlet used to test server.
* <P>
* Taken from More Servlets and JavaServer Pages
* from Prentice Hall and Sun Microsystems Press,
* http://www.moreservlets.com/.
* &copy; 2002 Marty Hall; may be freely used or adapted.
public class HelloServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String docType =
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
"Transitional//EN\">\n";
out.println(docType +
"<HTML>\n" +
"<HEAD><TITLE>Hello</TITLE></HEAD>\n" +
"<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<H1>Hello</H1>\n" +
"</BODY></HTML>");
please help me out of it...
thank you all...

hi man,
thanks for the classpath, and i already did it in system environment.
but it can not work either...
do i really have to download the API, so where i have to put it after i download it...

Similar Messages

  • Trying to compile my first Java program !

    Hi,
    I am a new programmer.Looking to clarify a very simple doubt while compiling my first java program.
    I have set up jdk in the following directory on my PC , E:\j2sdk1.4.1_01\bin.
    Now when I create the first AClass.java file in the AClass directory under bin and try and compile it I get the following error.
    E:\j2sdk1.4.1_01\bin>java E:\j2sdk1.4.1_01\bin\AClass\AClass
    Exception in thread main
    java.lang.NoClassDefFoundError: E:\j2sdk1/4/1_01\bin\AClass\AClass
    Kindly help me how to fix this.

    hi,
    Just do this,
    set path & classpath either in the system environment veriable or in the command prompt as shown below.
    set PATH=%PATH%;E:\j2sdk1.4.1_01\bin
    set CLASSPATH=%CLASSPATH%;.
    Be careful, there is a trailing DOT (.) at the end of the classpath, and that is what needed for
    the JVM to find the class file. with this you would be able to run your program. Infact JDK1.4.x and higher
    doesn't requires classpath to be set, your system classpath variable needs a DOT (.)
    at the end of the classpath variable defined in the environment variable section of your computer or
    in the command prompt you need it to set it once for the current command prompt window before
    executing any java program.
    Regards
    Goodieguy

  • How to compile and Run servlet Program

    Hi,
    pls help me the following doubt
    i am using Tomacat 4.1 server.
    1. Where is save Servlet program?
    2. How to set classpath?
    3. how compile and run?
    bye
    Mathi

    1. Where is save Servlet program?
    2. How to set classpath?
    3. how compile and run?
    http://www.coreservlets.com

  • Compiling my first servlet

    I tried to compile HelloWorldServlet.java(taken from sunexamples) stored in JavaWebServer2.0\servlets.
    I have JavaWebServer2.0 and have included servlet.jar in my environment variables.
    I was getting an error can't find class sun/tools/javac/main.
    Then,I took tools.jar from my jdk1.3, and pasted in JavaWebServer2.0\lib and included tools.jar in environment variables.
    Now I get errors:
    java.lang.NoClassDefFoundError:java/util/ArrayList
         at sun.tools.util.CommandLine.parse(Compiled Code)
         at sun.tools.javac.Main.compile(Compiled Code)
         at sun.tools.javac.Main.main(Main.java:729)
    PLEASE HELP ME.
    Is it wrong to copy-paste tools.jar?How can I compile?

    Here is part of a batch file I use for my command line compiling.
    SET JAVA_HOME=C:\jdk1.3.1_09
    SET CLASSPATH=.;C:\jdk1.3.1_09\lib\jt400.jar;C:\jdk1.3.1_09\lib\tools.jar;C:\jdk1.3.1_09\lib\classes12.zip;C:\jdk1.3.1_09\lib\jregex1.2_01.jar
    SET PATH=c:\jdk1.3.1_09\binCreate a file with extension .bat and add this. Make changes to your jars and directories as needed.

  • Compilation error for First Servlet program

    Hi,
    I have go the following program from a book bu is giving me a long list of errors maybe I have no imported the proper package.
    import java.servlet.*;
    import java.io.*;
    public class Brat extends GenericServlet
    public void init (ServletConfig sc)
    throws ServletException
    System.out.println("I don wana wake up");
    public void service (ServletRequest req, ServletResponse res)
    throws ServletException
    try{
    ServletOutputStream sos=res.getOutputStream();
    sos.println("I dont wanna do anyhing");
    sos.close();
    catch(IOException ioe) {ioe.printStackTrace();}
    public void destroy()
    System.out.println("I dont wana go to bed");
    Its giving me symbol not resolve errors for the
    following symbols
    ServletException, ServletConfig, ServletResponse etc.
    How can I get around with these errors?
    Zulfi.

    Sorry, but i handled with Servlets some time ago.
    Servlets are not contained in the standard SDK.
    There has been a servlet development kit, but it seems not to exist any more. (I cant't find it)
    But servlet technology is included in java server pages and other web applications, so you have to download i.g. J2EE SDK and to install it, to find the classes you need.
    (It's included in other packages too, i think.)
    http://java.sun.com/products/jsp/download.html
    If you've installed the used packages, then include only the packages you need. (Doc's should help)
    Make shure that the packages are included in your classpath.
    (Have been the files server.jar and servlet.jar in "former" times.)
    Sorry, but i can't give more advice, 'cause im not up to date with this subject.
    Maybe someone else can help?
    Good luck again.

  • First Servlet Program: Whats the error now?

    I have changed my web.xml file. Its small now:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
    <web-app>
    <servlet>
    <servlet-name>Brat</servlet-name>
    <servlet-class>Brat</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>Brat</servlet-name>
    <url-pattern>/Brat</url-pattern>
    </servlet-mapping>
    </web-app>
    My URL is:
    http://localhost:8080/examples/Brat
    & I have copied Brat.class in the webapps,
    webapps/examples, webapps/examples/servlets direcories but still its complaining about its location. I am getting following errors at different imes:
    HTTP Status 503 - Servlet Brat is currently unavailable
    The requested service (Servlet Brat is currently unavailable) is not currently available.
    A Servlet Exception Has Occurred
    Exception Report:
    javax.servlet.ServletException: Wrapper cannot find servlet class Brat or a class it depends on
         at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:797)
         at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:602)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:231)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:225)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2252)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:446)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:163)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:875)
         at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:952)
         at java.lang.Thread.run(Thread.java:484)
    Root Cause:
    java.lang.ClassNotFoundException: Brat
         at org.apache.catalina.loader.StandardClassLoader.loadClass(StandardClassLoader.java:1111)
         at org.apache.catalina.loader.StandardClassLoader.loadClass(StandardClassLoader.java:976)
         at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:792)
         at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:602)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:231)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:225)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2252)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:446)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:163)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:875)
         at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:952)
         at java.lang.Thread.run(Thread.java:484)
    Can somebody plz help me?
    Zulfi.

    C:\, C:\WINNT are directories unrelated to Tomcat that Tomcat doesn't know about (unless you told it about them in the conf/server.xml file).
    A simple solution without editing your server.xml file is to use Tomcat's ROOT directory.
    This directory is by default <Tomcat install directory>\webapps\ROOT
    (For me it's : C:\Program Files\Tomcat 4.1\webapps\ROOT).
    In this ROOT directory you have the WEB-INF directory wich contains the web.xml file.
    Under this WEB-INF directory create a directory called "classes" and put a copy of you servlet class file in it.
    The complete path of your servlet class file then should be
    <Tomcat install directory>\webapps\ROOT\WEB-INF\classes\Brat.class
    Try this and report if it worked.

  • Compiling my first servlet page

    Hi,
    Im not able to compile my servlet.The servlet code is in desktop\java.The servlet.jar is in c:\program files \ apache tomcat 4.0\common\lib
    when i give this command
    javac HelloServlet.java -classpath " c:\--------" it is not working.I dont know whether this is correct.Please help me out.

    Adding the servlet.jar to tomcat won't make the java compiler know where it is unless the code is called from an application in the web container.
    use javac -cp "filename"
    Otherwise I'd suggest you'd get an IDE to which you add the jar and then compile using the IDE.
    Don't waste your time with javac!

  • Can't compile the first sample in crossbridge

    when i'm trying to run make FLASCC=/cygdrive/c/crossbridge/sdk FLEX=/cygdrive/c/flex_sdk  in run.bat it gives the error "Unable to launch the Java Virtual Machine". i have already downloaded the 64-bit java and the flex sdk. i have also downloaded the flash builder.
    any help in this matter will be appreciated. thanks in advance

    ALWAYS Google your problem first if you Google this one you will likely find some helpful solutions http://tinyurl.com/oxkvhd3
    Anyway, you should probably check your Windows CLASSPATH envirnoment variable is set correctly as the next step.

  • Unable to run Servlet program using J2EE SDK

    Hello,
    i am a newbie to all this j2ee stuff and servlets even.so the problem that i have maybe a very common one and i hope that most of you may have a fix to it...
    i use J2EE SDK to compile and run Servlet programs.I have a Servlet program with the class name defined as
    public class MyServlet extends HttpServlet ....
    the file is stored as MyServlet.java
    i set the CLASSPATH variable so that the required classes for the compilation of the program can be located.
    the program compiles without any glitches.
    However when i run the program by saying
    java MyServlet
    ( i dont think its any different to run servlet code is it?)
    i get the message
    java.lang.NoClassDefFoundException:MyServlet
    Can someone suggest a remedy?
    thank you
    -NDK

    First, I don't understand what you are trying to do. Running a servlet ?
    Servlets are ran by an application server ! (Apache Tomcat ....).
    Second, is your class in any package ?

  • Please help me to use javamail to send mail in servlet program

    hi
    i want to send simple mail from user [email protected] to user [email protected] using servlet program
    i can't compile the javamail demo program servlet "JavaMailServlet.java".
    i have this exception
    Note: SendMailServlet.java uses or overrides a deprecated API.
    Note: Recompile with -deprecation for details.
    i don't no how to do
    please help me if you have code
    thank's

    Given that you're having problems with your [url http://forum.java.sun.com/thread.jsp?forum=43&thread=536278&tstart=0&trange=30]demo mail code as well as your demo servlet code, perhaps you would be better served by learning about JavaMail, servlets, and perhaps Java in general (for example - the meaning of deprecated). Then you may be able to build your own servlet for handling mail or at least will be able to revise the demo code found elsewhere.
    Of course, if the purpose is really not to learn how to use Java, JavaMail, servlets, etc. but to simply create something that works then you could always hire someone to write the program for you.
    This is not intended to be rude or anything - just an observation and some food for thought.
    &#8734; brewman &#8734;

  • How to compile and run servlets in Eclipse?

    Does somebody known how can I compile and run servlets in Eclipse IDE? I've added and configured Tomcat's plugin. I've created a project with my example servlets source, and I don't know what farther. How do I have compile it without main method? I must add web.xml file from Tomcat's directory into projects in Eclipse and modify it?
    THX Chudzik

    Try googling for "eclipse servlet", surely someone has written instructions.

  • I have jsdk2, but I can't compile servlet program

    I have jsdk2 version. which create in my c:\ dirve a folder jdk1.3. I do all the program from that. But I found that some of the class files of Servlet (servletRespose etc ) is missing. What I do to recover that. Even I can't compile any servlet program from that. Pls reply to my problems.
    Regards.
    Ranjan

    The Servlet API is part of J2EE (Java 2 Enterprise Edition). It is not included in the Standard Edition.
    So you need to download and install the J2EE reference implementation or another servlet engine such as Apache Tomcat ( http://jakarta.apache.org/tomcat ). Don't forget to put the Tomcat JAR files in your CLASSPATH when compiling your servlet program.
    Jesper

  • Can't compile Servlet program(error in setting classpath in XP)

    I encountered a similar problem as 'hereispaddy'.
    "I have recently written a servlet program. When I compile the program (let's say "HelloWorld.java"), I've got the following error message:
    package javax.servlet does not exist
    I've download the class files and set the classpath already. Have I missed anything? "
    i would like to ask, how to set the following in Windows XP:
    set CATALINE_HOME=C:\PROGRA~1\APACHE~1.0
    set CLASSPATH=.;%CATALINE_HOME%\COMMON\LIB\SERVLET.JAR;C:\JDK1.4\BIN;
    *ive tried in control panel->system->advanced->environment variables->
    variable name:CATALINE_HOME
    variable value:C:\Program Files\Apache Tomcat4.0 (and)
    variable name:CLASSPATH
    variable value:.;%CATALINE_HOME%\common\lib\servlet.jar;C:\jdk1.4\bin
    but failed!
    Could anyone kindly tell me what's wrong with my setting?
    Thx a lot!!!

    Does Tomcat work? Can run the examples on the home page?
    The only suggestion I have at this point is to get rid of the spaces in
    C:\Program Files\Apache Tomcat4.0
    But I am still in Win98 , so I am just guessing.

  • Problem in compiling aa servlet program

    I have installed jsdk1.4.2_13
    And also installed tomcat 5.0.28
    I have set
    CATALINA_HOME==C:\Program Files\Tomcat\jakarta-tomcat-5.0.28
    JAVA_HOME ==C:\j2sdk1.4.2_13
    CLASS_PATH==
    C:\Program Files\Tomcat\jakarta-tomcat-5.0.28\common\lib\servlet-api.jar;
    C:\Program Files\Tomcat\jakarta-tomcat-5.0.28\common\lib\jsp-api.jar
    PATH ==C:\j2sdk1.4.2_13\bin;C:\Program Files\Tomcat\jakarta-tomcat-5.0.28\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem
    -->My java programs are compiling
    -->I can run tomcat server , And also can see starting page of "http://localhost:8080/"
    But I am not able to compile servlet program
    MY sevlet program is
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class HelloServlet extends HttpServlet {
    public void doGet(HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    String docType =
    "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
    "Transitional//EN\">\n";
    out.println(docType +
    "<HTML>\n" +
    "<HEAD><TITLE>Hello</TITLE></HEAD>\n" +
    "<BODY BGCOLOR=\"#FDF5E6\">\n" +
    "<H1>Hello</H1>\n" +
    "</BODY></HTML>");
    ERRORS are:
    Pakage javax.servlet does not exist
    Pakage javax.servlet.http does not exist
    cannot resolve symbol HttpServletRequest
    and similar errors
    can anyone guide me?
    Message was edited by:
    Learn

    it's not CLASS_PATH, it's CLASSPATH.
    Directory paths with spaces in them are problematic. Surround them with double quotes.
    I think the best thing is not a CLASSPATH environment variable. Better to use the -classpath option on javac.exe when you compile.
    So your command to compile might look something like:
    javac -classpath .;"C:\Program Files\Tomcat\jakarta-tomcat-5.0.28\common\lib\servlet-api.jar" *.java%

  • Problem compiling my first program; Please Help me!

    Please HELP, what am I doing wrong?
    For over 5hours I have been trying to figure out how to compile a simple Hello world program using sdk1.3.1_02/j2re1.3.1_02 and I am getting the following errors: helloworld.java:2 cannot resolve symbol
    symbol : class string
    location : class helloworld
    cannot reolve the string symbol
    symbol : class out
    location : package system
    I want to program in java so badly but I am trying to get my environment set so that I can take off. To compile my first program has been a disaster!!
    This is my path:
    SET PATH=C:\WINDOWS;C:\WINDOWS\COMMAND;C:\JDK1.3.1_02\BIN
    Thanks very much in advance
    ::(

    Java is case sensitive,
    use String instead of string. and System.out instead of system.out
    Sudha

Maybe you are looking for

  • Function to change Boarder Look and feel of Jframe - Not working

    Hi all, In the given SSCE, the functionpublic void changeButtonColor(Component[] comps) to change the border look and feel of JFrame is not working.Please help. import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import ja

  • DBMS_JAVA Problem

    I have Four set of questions :- 1) I have granted the execute permission to the DBMS_JAVA package to SCOTT user, When I try to execute, it gives error : call dbms_java.grant_permission 'scott','SYS:java.lang.RuntimePermission', 'readFileDescriptor','

  • Material doument number range

    Hi All in our SAP system we have 2 company codes but material doument number range is same for both the company codes . how to set it at company code specific and / or Plant specific? I have checked with T code OBH1 but it is related to FI doc types

  • Double Vision after updating to 10.4.6

    After upgrading to 10.4.6 I am getting a screen that has "double vision" ... as soon as the loading Screen with the blue bar comes up, and it remains this way. If I reset the Pram at startup, this problem does not happen. This is a new issue after in

  • Edge Animate CC Crashing

    Hey, hoping to get some help here. in the video below you can see how my rulers and and selection tools disappear. if i continue to work like this it will either crash or give me different errors. I've reinstalled several times and even wiped my comp