I can't  compile a servlet

Can I complie a servlet with javac?
Im a new user, when i try to compile a servlet from javac myservlet.java
The compiler send several errors, it doesn't recognise the class of servlets.
My Enviroments' vars are:
PATH = C:\JDK1.4\BIN
CLASSPATH = .;C:\JBuilder8\thirdparty\jakarta-tomcat-4.1.12-LE-jdk14\common\lib\
I don't know if i'm doing wrong
I hope your answers

You need to add sevlet.jar to your classpath, which is located in TOMCAT_HOME/common/lib

Similar Messages

  • Can not compile a servlet!

    Hi!
    so.. I import
    import javax.servlet.*;
    import javax.servlet.http.*;
    ..and then I write mi servlet. But javac tels me :
    HttpServlet .. no such thing !
    What shall I do ?

    do you have servlet.jar included in your classpath? do you have a servlet runner? if not, go to jakarta.apache.org and download tomcat.

  • 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

  • I can't access able to compile the servlet that access EJB methods

    Hello,
    i have written i servlet (TestServlet.java) to access the ejb(SignOn) method(validateUser(userId,Password)) but i can't compile this servlet.it shows this type error.can anybody help me to do it complete.i have written the ejb & servlet in (d:\ejb\src\demo).
    D:\riazejb\src\demo>javac TestServlet.java
    TestServlet.java:15: cannot find symbol
    symbol : class SignOnHome
    location: class demo.TestServlet
    SignOnHome signOnHome;
    ^
    TestServlet.java:16: cannot find symbol
    symbol : class SignOn
    location: class demo.TestServlet
    SignOn signOn;
    ^
    TestServlet.java:23: cannot find symbol
    symbol : class SignOnHome
    location: class demo.TestServlet
    signOnHome = (SignOnHome)PortableRemoteObject.narrow(objref,SignOnHome.c
    lass);
    My servlet code is
    package demo;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;
    import javax.naming.*;
    import javax.ejb.*;
    import demo.*;
    import javax.rmi.PortableRemoteObject;
    public class TestServlet extends HttpServlet {
    SignOnHome signOnHome;
    SignOn signOn;
    public void init(ServletConfig config) throws ServletException {
    //Look up home interface
    try {
    InitialContext ctx = new InitialContext();
    Object objref = ctx.lookup("demo/SignOn");
    signOnHome = (SignOnHome)PortableRemoteObject.narrow(objref,SignOnHome.class);
    } catch (Exception NamingException) {
    NamingException.printStackTrace();
    public void doGet (HttpServletRequest request,HttpServletResponse response)
    throws ServletException, IOException
    PrintWriter out;
    response.setContentType("text/html");
    String title = "EJB Example";
    out = response.getWriter();
    out.println("<html>");
    out.println("<head>");
    out.println("<title>Hello World Servlet!</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("<p align=\"center\"><font size=\"4\" color=\"#000080\">Servlet Calling Session Bean</font></p>");
    try{
    // MyTestSession beanRemote;
    SignOn signOn;
    signOn = (SignOn)signOnHome.create();
    out.println("<p align=\"center\"> Message from Session Bean is: <b>" + signOn.validateUser(student,password) + "</b></p>");
    signOn.remove();
    }catch(Exception CreateException){
    CreateException.printStackTrace();
    out.println("<p align=\"center\"><a href=\"javascript:history.back()\">Go to Home</a></p>");
    out.println("</body>");
    out.println("</html>");
    out.close();
    public void destroy() {
    System.out.println("Destroy");
    Thanks in advance.
    Riaz

    Have you added the EJB client JAR to classpath for compilation?
    java -classpath "%CLASSPATH%;<<EJBCLient JAR path>> *.java

  • Can't find the servlets package when compiling

    Hi,
    My problem is that when I compiling my servlets so can't the compiler find the two packages javax.servlet and javax.servlet.http.
    Why?
    Please can someone help me with this problem!
    HelloServlet.java:2: package javax.servlet does not exist
    import javax.servlet.*;
    ^
    HelloServlet.java:3: package javax.servlet.http does not exist
    import javax.servlet.http.*;

    OK,
    It seems like it will work with your proposal to. But now I have a new problem that you maybe can solve for me. That is when I try to test the following (from the book More Servlets and JavaServer Pages):
    Test 3: A Servlet That Uses Packages and Utilities
    The final servlet you should test to verify the configuration of your server and development environment is one that uses both packages and utility classes. HelloServlet3.java is a servlet in the moreservlets package that uses the ServletUtilities class to simplify the generation of the DOCTYPE (specifies the HTML version--useful when using HTML validators) and HEAD (specifies the title) portions of the HTML page. Those two parts of the page are useful (technically required, in fact), but are tedious to generate with servlet println statements.
    Since both the servlet and the utility class are in the moreservlets package, they should go in the moreservlets directory. If you get compilation errors, go back and check your CLASSPATH settings--you most likely forgot to include the top-level development directory. I've said it before, but I'll say it again: your CLASSPATH must include the top-level directory of your package hierarchy before you can compile a packaged class that makes use of another class from the same package. This requirement is not particular to servlets; it is the way packages work on the Java platform in general. Nevertheless, many servlet developers are unaware of this fact, and it is one of the (perhaps the) most common errors beginning developers encounter.
    Once you compile HelloServlet3.java (which will automatically cause ServletUtilities.java to be compiled), put HelloServlet3.class and ServletUtilities.class in install_dir/webapps/ROOT/WEB-INF/classes/moreservlets. Then, access the servlet with the URL http://localhost/servlet/moreservlets.HelloServlet3. You should get a simple HTML page that says "Hello (3)".
    This works not for me! I will get this message when I try to compile HelloServlet3.java:
    C:\Apache-Tomcat-4.1.27\ServletsDevel>javac HelloServlet3.java
    HelloServlet3.java:23: cannot resolve symbol
    symbol : variable ServletUtilities
    location: class moreservlets.HelloServlet3
    out.println(ServletUtilities.headWithTitle(title) +
    ^
    1 error
    Do you know what the problem is?

  • Can I compiler servlet with java compiler?

    Can I compiler servlet with java compiler?
    Here is an example of it:
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    public class HelloWorldServlet extends HttpServlet
              protected void doGet(HttpServletRequest request,
              HttpServletResponse response) throws ServletException , IOException
                        response.setContentType("text/html");
                        PrintWriter out = response.getWriter();
                        StringBuffer sb = new StringBuffer();
                        sb.append("<html><body><h1>");
                        sb.append("Hello World");
                        sb.append("</h1></body></html>");
                        out.print(sb.toString());
                        out.close();
         }

    Can I compiler servlet with java compiler?
    yes.
    just include the correct jarfiles in your classpath.

  • How can I run a servlet with tomcat

    I'm a new learner in servlet,I recently write a servlet program,when I compile it,the compiler throws the error
    "package javax.servlet.http does not exist",I have put the servlet.jar(which exist in d:\tomcat\bin directory) file into the classpath directory;my servlet source files are in D:\tomcat\webapps\mywork\web-inf\classes\com\stardeveloper\servlets;
    "com.stardeveloper.servlets" is the package for my servlet source files,so I have write the sentence "package com.stardeveloper.servlets;" in my servlet source file.
    I don't know how to resolve this problem.can you give me a help?

    servlet.jar doesn't exist in the folder you mentioned, but rather, in C:\tomcat40\common\lib, so this should be included in your classpath, the other thing you should care about is how you compiled your servlets, so that the package statement match the hirarchy of the file.
    regards

  • How to Compile/Run servlet in Tomcat 4.1

    Hi All,
    iam trying to compile my servlet program in tomcat4.1.. but its showing an error
    in the import statement..
    UN SOLVABLE SYMBOL... but the import ststement is correct...
    can any one help ... is there i have to set any path for compiling/running the servlet...
    Thanks in Advice

    hi thanks for your reply
    i have loaded tomcat4.1 exe -- for windows i am starting the tomcat server by clicking from the start menu..
    i dint set any env variable .. tell me how to set...
    regards
    ijay

  • Create problem when compiling the servlet

    hi,
    i got a problem when i compile a servlet
    when i try to compile the servlet, it shows that it could
    not found the classes like httpservlet, etc.
    means the classes of the servlet
    i am using the j2sdk1.4.1 edition,
    i had include the javax.servlet.*; in the program
    please tell me what can be the problem & especially any solution for that

    the javax.servlet package and it's sub packages (javax.servlet.http, javax.servlet.jsp, javax.servlet.jsp.tagext) are not included with the Standard Edition. These packages are part of the Enterprise Edition. Check out this link for download:
    http://java.sun.com/j2ee/sdk_1.3/

  • I can't compile this, why?

    I do not possess any means of compiling any .java file that imports javax.* or anything J2SE-related, thus, I have to compile it remotely on a remote host (www.myjavaserver.com), however, for some reason this file will not compile but will not produce any errors, warnings, or any display of any kind - but no .class file is ever found.
    import java.io.*, java.util.*, javax.servlet.*, javax.servlet.http.*;
    * Borrowed from http://forum.java.sun.com/thread.jspa?threadID=703076
    * @access public
    * @author Phil Powell
    public class RequestParameterResetter extends HttpServletRequestWrapper {
        private HttpservletRequest origRequest;
        private Map<String, String> parameterMap;
        public RequestParameterResetter(HttpServletRequest request) {
            super(request);
            origRequest = request;
            parameterMap = new HashMap<String,String>();
        public String setParameter(String key, String value) {
            String oldValue = parameterMap.put(key,value);
            if (oldValue == null) oldValue = origRequest.getParameter(key);
            return oldValue;
        public String getParameter(String key) {
            String value = parameterMap.get(key);
            if (value == null) value = origRequest.getParameter(key);
            return value;
    }Could someone tell me what I'm missing in order for this to properly compile?
    Thanx
    Phil

    Sorry I can't do that, as much as I want to. My
    computer is very ancient and has too little memory to
    run any kind of server program, especially a
    Java-related one. I tried with Eclipse a while back
    (2 years ago and never figured it out, way too hard
    in spite of my PC's inability to interact with it)
    nearly destroyed my machine with it.You actually don't need to run any server. You just need to get the .JAR files (you should try to get the same server and version that you deploy on ... but that may not be possible). Then you put them in your Java Classpath, and you will be able to compile (from command line, or whatever). You could then un-install the server if you wanted to...
    >
    That means I can only compile J2SE formatted classes
    remotelyThat would be J2EE. J2SE is the standard edition, where you get the compiler, java.lang.String, java.util.Date, and all the rest of the core stuff. J2EE is the enterprise edition for getting the javax.servlet packages (among others).
    More comments on how you might change added as comments in the code...
    on www.myjavaserver.com - provided it is
    working.
    I made the changes necessary and still can't compile
    it!
    package ppowell;
    import java.io.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    * Borrowed from
    m
    http://forum.java.sun.com/thread.jspa?threadID=703076
    * @version JSDK 1.2
    The class is a Java 5.0 class, it won't compile to JSDK 1.2.
    Ask myjavaserver.com to see how you can get ahold of the error logs so you can see what messages are generated.
    * @author Phil Powell
    * @package PPOWELL
    public class RequestParameterResetter extends
    HttpServletRequestWrapper {
    private HttpServletRequest origRequest;
    private Map<String, String> parameterMap;//if you want to use non JSE 5.0, then this line should be:
    //        private Map parameterMap;
    >
    public
    blic RequestParameterResetter(HttpServletRequest
    request) {
    super(request);
    origRequest = request;
    parameterMap = new HashMap<String,String>();//if you want to use non JSE 5.0, then this line should be:
    //            parameterMap = new HashMap();
    public String setParameter(String key, String
    ring value) {
    String oldValue = parameterMap.put(key,value);//if you want to use non JSE 5.0, then this line should be:
    //        String oldValue = (String) parameterMap.put(key,value);
    if (oldValue == null) oldValue = origRequest.getParameter(key);
    return oldValue;
    public String getParameter(String key) {
    String value = parameterMap.get(key);//if you want to use non JSE 5.0, then this line should be:
    //            String value = (String)parameterMap.get(key);
    if (value == null) value =
    value = origRequest.getParameter(key);
    return value;

  • Can't compile this sourcecode

    why i can't compile this source code??
    if i not mistaken the error like this "can't read bla..bla(i din't remember)"
    (i've install all the java package..)
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.Date;
    import java.util.Hashtable;
    * Date Servlet
    * This is a simple servlet to demonstrate server-side include
    * It returns a string representation of the current time.
    * @author Scott Atwood
    * @version 1.12, 08/29/97
    public class DateServlet extends HttpServlet {
    public void service(HttpServletRequest req, HttpServletResponse res)
         throws ServletException, IOException
    Date today = new Date();
    res.setContentType("text/plain");
    //getOutputStream ni aper?
    ServletOutputStream out = res.getOutputStream();
    out.println(today.toString());
    public String getServletInfo() {
    return "Returns a string representation of the current time";

    Try it again. And this time write down the error message you get so you can ask a coherent question.

  • Compiling a Servlet that uses JavaBean

    I have a servlet that will get data from a JavaBean which is created before in a jsp file. While I trying to compile the servlet I am getting this message:
    --------------------Configuration: JDK version 1.3 <Default>--------------------
    Command : "C:\jdk1.3\bin\javac.exe" -d "C:\jakarta-tomcat-3.2.1\webapps\ROOT\WEB-INF\classes" C:\jakarta-tomcat-3.2.1\webapps\ROOT\WEB-INF\classes\MyServlet.java
    Directory : C:\jakarta-tomcat-3.2.1\webapps\ROOT\WEB-INF\classes
    C:\jakarta-tomcat-3.2.1\webapps\ROOT\WEB-INF\classes\TasitKayitGirisi.java:19: cannot resolve symbol
    symbol : class SimpleBean
    location: class MyPackage.SimpleBean
         SimpleBean simpleBean = (SimpleBean) session.getAttribute
    ^
    ("simpleBean");
    C:\jakarta-tomcat-3.2.1\webapps\ROOT\WEB-INF\classes\MyServlet.java:19: cannot resolve symbol
    symbol : class SimpleBean
    location: class MyPackage.SimpleBean
         SimpleBean simpleBean= (SimpleBean) session.getAttribute("simpleBean");
    ^
    2 errors
    Process completed.
    Where is the problem. SimpleBean is successfully being initializing in my jsp file. But I couldn't compile my servlet that will get data from that bean. Both my servlet and bean are in the same package. I am using JCreator to compile servlets. I think the problem is the compile string that JCreator uses. Can you help me. Thx in advance.

    Looks like an import Problem.
    The Compiler is not able to "see" the SimpleBean Class.
    Take care of the Classpath and your imports.
    Happy Coding. :-)

  • How to compile a servlet

    I am trying to compile a servlet using the import javax.servlet.*;
    import javax.servlet.http.*; packages. But the only thing I keep getting is :
    BasicServlet.java:1: package javax.servlet does not exist
    import javax.servlet.*;
    ^
    BasicServlet.java:2: package javax.servlet.http does not exist
    import javax.servlet.http.*;
    ^
    BasicServlet.java:6: cannot resolve symbol
    symbol : class HttpServlet
    location: class BasicServlet
    public class BasicServlet extends HttpServlet
    I have included the servletapi2_1_1-win package from the sun site containing the servlet.jar in my classpath. Still it refuses to compile. Besides does anybody know how to compile using the servlet packages available in Tomcat or j2ee, both of which I have on my machine , but can't figure what to include.
    Please help.
    ^

    have you actually included the servlet.jar file in your classpath or just the directory, as you need to explicity declare jar files in the classpath...
    javac -classpath %CLASSPATH%;C:\[servlet-jar-path]\servlet.jar Servlet.class

  • Can't see my Servlet/JSP outputs

    {color:#0000ff}Hello there Java gurus,
    I'm really excited about Java but there seems to be something i'm missing out that is slowing me down. I understand the logic behind the Servlet and JSP technologies - having context root in the webapps subdirectory of the Apache Tomcat, placing other directories like servlets, WEB-INF, classes etc in their respective places and copying .class, .xml, and .html into the proper directory of webapps subdirectories- but still I can't execute properly to view the outputs of even the simplest Servlet and JSP codes.
    When I tried compiling my Servlet Java file to produce a .class file, it gave an error of "javax.servlet does not exist". What can I do again to make me execute my Servlets, because there's truely no javax.servlet in the Java subdirectory of my Program Files.
    Thanks in advance for making this guy smile.
    ***Smiles***{color}

    Ednut wrote:
    Thanks cutton_m for the response, but if you can be clearer on how to get the .jar files or any other file that'd help, i'd be happier. My jakarta-tomcat-5.0.25is successfully installed, and I really don't understand what u mean by j2ee libraries coming with the tomcat's container.
    You need the jars in your classpath.
    The jars came with the J2EE container - in your case tomcat.
    Just what should I do to get the output of my Servlets/JSP codes viewable?Get to build first would be a start.

  • Unable to compile a servlet

    Iam not able to compile a servlet.I have included the servlet.jar in my classpath.
    My java compiler path is c:\jdk1.3 and JWS path is d:\jws2.0
    I get "Unable to resolve symbol" error which points to HttpServlet and javax.servlet.
    Can anybody help me in this.

    the following is the code in build.xml
    <? xmlversion="1.0"?>
    <project name=" test" default="compile" basedir=".">
    <property name="src" value="."/>
    <property name="build" value="build"/>
    <target name="init">
    <mkdirdir="${build}"/>
    </target>
    <target name="compile" depends=" init">
    <!- - Compile the java code - ->
    <javac srcdir="${src}" destdir="${build}"/>
    </target>
    </project>
    while building it says "The processing information
    must begin with the name of the target"
    what does it mean and where i have done mistake.
    please clarifyIs that code exactly copied and pasted from your build file? If so, you will need to make some modifications:
    1. It looks like you have a space between the "?" and "xml" on the first line. There cannot be a space here. But you do need a space between "xml" and "version". So change your code to look like this:
    <?xml version="1.0"?>2. You have an extra space in your <project> element's "name" attribute. There should not be a space here. Change this line to look like this:
    <project name="test" default="compile" basedir=".">
    //             ^
    //             |
    //       yours had a space hereThere are several places in your build file where you have spaces that should not be there. Go through the file and remove the spaces (such as in the line depends=" init").
    Let me know if that changes anything for you. Oh, and one more thing -- make sure you are in the same directory as your build.xml file! Keep at it, you will get it.

Maybe you are looking for