Problems to compile a servlet

Hi, i have a problem to compile a servlet, i will try to explain my problem easily...
i have a JavaBena class int he directory.....C:\Programmi\Apache Software Foundation\Tomcat 6.0\webapps\ROOT\WEB-INF\classes......and i have compiled it by DOS commands, everyhting has gone well!
i have a Servlet class in the same directory where it situated the JavaBean. i compile the Servlet as well as i have done with the Javabean, by DOS commans, including the Tomcat servlet api.
this is the command which i use to compile the servlet.......javac ServletRegistraUtente.java -classpath "C:\Programmi\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar".....
but everything i get this error...
C:\Programmi\Apache Software Foundation\Tomcat 6.0\webapps\ROOT\WEB-INF\classes>javac ServletRicercaUtente
.java -classpath "C:\Programmi\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar"
ServletRicercaUtente.java:20: cannot find symbol
symbol : class BeanRicercaUtente
location: class ServletRicercaUtente
^
ServletRicercaUtente.java:20: cannot find symbol
symbol : class BeanRicercaUtente
location: class ServletRicercaUtente
BeanRicercaUtente m_BeanRicercaUtente = new BeanRicercaUtente();
^
2 errors
C:\Programmi\Apache Software Foundation\Tomcat 6.0\webapps\ROOT\WEB-INF\classes>
these are the 2 classes....
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
import JavaBean.BeanRicercaUtente;
public class ServletRicercaUtente extends HttpServlet
     public void doPost(HttpServletRequest request, HttpServletResponse response)
     throws IOException, ServletException
          ServletContext sc;
          RequestDispatcher rd;
          try
               BeanRicercaUtente m_BeanRicercaUtente = new BeanRicercaUtente();
               request.setAttribute("m_BeanRicercaUtente", m_BeanRicercaUtente);
               String codiceFiscale = request.getParameter("codice");
               m_BeanRicercaUtente.effettuaRicerca(codiceFiscale);
               sc = getServletContext();
               rd = sc.getRequestDispatcher("/risposta.jsp");
               rd.forward(request, response);
          catch(Throwable theException){}
import java.sql.*;
public class BeanRicercaUtente
     String nome, cognome, indirizzo, telefono;
     public void effettuaRicerca(String codiceFiscale)
          try
               Class.forName("com.mysql.jdbc.Driver");
               String url = "jdbc:mysql://.................";
               Connection con = DriverManager.getConnection(url);
               Statement cmd = con.createStatement();
               String qry = "SELECT ..................";
               ResultSet res = cmd.executeQuery(qry);
               while (res.next())
                    cognome = res.getString(1);
                    nome = res.getString(2);
                    indirizzo = res.getString(3);
                    telefono = res.getString(4);
               res.close();
               cmd.close();
               con.close();
          catch (SQLException e)
               e.printStackTrace();
          catch (ClassNotFoundException e)
               e.printStackTrace();
i would be glad to get help about it...! :) thanks!

i am sorry, but in the first class i have not written "import JavaBean.BeanRicercaUtente;"
i have only these imports...
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;

Similar Messages

  • 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/

  • 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%

  • Compiling Java Servlet with Depricated Methods

    I have a problem of compiling Java servlets that contain depricated methods. If you compile against modern version of servlet.jar I see depricated methods error messages and if I use a very old servlet.jar it cannot find newer methods. What is is the best solution in this case?
    Thank you,
    Boris.

    The best thing to do would be compile your code with the -depreciated option to find which methods have been depreciated and the refactor your code to remove them.
    The next best thing is to ignore the messages (they are warnings not errors) and your code should still work

  • Problem in compiling servlet

    hi
    i'm trying to compile a simple servlet
    my directory structure is as follows
    c:\pr1
    |
    |____src
    |
    |______chservlet.java
    |
    |____classes
    |
    |____etc
    |
    |______web.xml
    c:\Tomcat5.0
    |
    |____webapps
    |
    |______ch1
    |
    |____WEB-INF
    |
    |____classes
    and the list of variables is as follows
    TOMCAT_HOME=c:\Tomcat 5.0\bin
    JAVA_HOME=c:\jsdk1.4
    classpath = %CLASSPATH%;c:\Tomcat 5.0\common\lib\servlet-api.jar
    now when i'm trying to compile the servlet by giving the following command
    javac -classpath ".;c:\Tomcat5.0\common\lib\servlet-api.ajr" -d classes c:\pr1\src\chservlet.java
    i'm getting the error package..
    javax.servlet.* doesnt exist
    can anybody help me at the earliest
    Regards
    jaismeen

    sorry guys..for starting each time new thread..just registered myself to the site yesterday after facing this problem..so cudnt get familiar with its working..
    i have given the commands as follows..
    set classpath=c:\Tomcat5.0\common\lib\servlet-api.jar,%classpath%
    set path=c:\jsdk1.4\bin;%path%
    javac c:\pr1\src\chservlet.java
    getting the following errors
    C:\>javac c:\pr1\src\chservlet.java
    c:\pr1\src\chservlet.java:1: package javax.servlet does not exist
    import javax.servlet.*;
    ^
    c:\pr1\src\chservlet.java:2: package javax.servlet.http does not exist
    import javax.servlet.http.*;
    ^
    c:\pr1\src\chservlet.java:5: cannot resolve symbol
    symbol : class HttpServlet
    location: class chservlet
    public class chservlet extends HttpServlet
    ^
    c:\pr1\src\chservlet.java:7: cannot resolve symbol
    symbol : class HttpServletRequest
    location: class chservlet
    public void doGet(HttpServletRequest req,HttpServletResponse res) throws IOExcep
    tion
    ^
    c:\pr1\src\chservlet.java:7: cannot resolve symbol
    symbol : class HttpServletResponse
    location: class chservlet
    public void doGet(HttpServletRequest req,HttpServletResponse res) throws IOExcep
    tion
    ^
    5 errors
    was just wondering.ihave windows xp..so does it effect in anyway(it shud not)
    and if name of the servlet is given wrong then it shudnt give these set of errors..it shud give kind a"cudnt find the file name"
    and i have checked the classpath..servlet-api.jar is present and is in this location
    c:\Tomcat 5.0\common\lib
    and i had tried giving the command
    jar -tvf servlet-api.jar..
    it gives the list of classes..which shows..its present in the directory
    jdk is present in c:\jsdk1.4
    location of servlet is c:\pr1\src\chservlet.java
    servlet code is as follows
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    public class chservlet extends HttpServlet
    public void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException
    PrintWriter out =res.getWriter();
    java.util.Date today= new java.util.Date();
    out.println("<html>"+
    "<body>"+
    "<h1 align=center>HF\'s Chapter1 Servlet<h1>"
    +"<br>"+today+"</body>"+"</html>");
    even i tried copynig servlet-api.jar in the same directory as the servlet and compiling it..
    it gives the same set of errors
    am just wondering what cud be the problem.sure..must b very smal..but i m not progressing much
    regards

  • Problem in compiling servlet class - using Tomcat

    Hi,
    I have a servlet pgm that I'm trying to compile.I using Tomcat application server.I have my servlet class in D:\servlet_wrk\project1\src
    and my deployment descriptor in D:\servlet_wrk\project1\etc
    my CLASSPATH var is set to C:\Sun\AppServer\jdk\bin
    and
    my PATH var is set to C:\Sun\AppServer\bin.
    When I compile my servlet class Ch1Servlet.java in the command line from the directory
    D:\servlet_wrk\project1 using the command
    javac -classpath D:\applications\tomcat-5.5.12\common\lib\servlet-api.jar -d classes src/Ch1Servlet.java,
    it says error:cannot read: src/Ch1Servlet.java
    Can somebody help me to solve this problem and help me to compile my servlet class.
    Thanks.

    Thanks...as u said I tried putting dir & found that
    my file was saved as Ch1Servlet.java.txt instead for
    Ch1Servlet.java......So that was a problem.Now I'm
    able to compile.Oh, yeah. Notepad will do that to you. I think when you save in Notepad if you put quotes around the name "Whatever.java" then it won't add the .txt.
    But on compiling I'm getting the following error
    package java.servlet.* does not exist
    package java.servlet.http.* does not exist
    package java.io.* does not exist
    Do u the reason for this??? The servlet stuff is java[b]x.servlet. For the io stuff, I don't know, I'd have to see your code. Either you have a typo or a corrupt installation.

  • Problems compiling a servlet

    Hello,
    I recently installed Tomcat 4.1.24 and I am trying to compile a servlet but with no success. The error I get is package javax.servlet does not exist. I have set up jdk1.3.1-3 and the environment paths. I have been successful in compiling regular java applications. I am currently just using the dos prompt and command line c:\javac somefile.java
    When I tried to compile a servlet, I ran into the javax.servlet error so I found a javax.jar file and added it to the jdk1/3/1-3\lib directory but the compile still fails.. I even tried to add it to the environment path but that still doesn't work...
    could someone tell me where I would need to add the javax.jar file? and what adjustment I need to make to be able to compile servlets?
    thanks in advance for any help
    gjcat777

    You need to get J2EE (Java 2 Enterprise Edition). Download it and install it. It's basically a couple of JAR files that you need to use. Under $J2EE_HOME/lib there is a file called J2EE.jar Include that JAR file into your project and carry on with your servlet development.

  • 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. :-)

  • Problem with Sessions in Servlets

    Hi,
    I'm having a problem with sesions with servlets. It seems that if someone logs into my website, which is running on all servlets, while another person is logged on, the second person gets the session of the first person.
    I'm using
    HttpSession session = request.getSession(true);to get the session in each page. The session contains a user object which shows if the user is logged in and what permissions.
    The session should be unique to the client computer right? Or am I jsut screwing this up big time?

    Yes, each client will have their own session. However, you may be testing incorrectly:
    In Firefox, for example, all instances of the application running on the same machine will share the same cookies, therefore the same session, and would be considered one client.
    MS IE will do the same if you use File - New to open a new wondow rather than clicking on the desktop icon.
    If the different clients are using different machines and still getting shared data, then you may be using class-level variables in the servlet, which would not be thread safe and could lead to your problems...
    public class MyServlet extends HttpServlet {
      String data;  //bad
      int moredata; //bad
      public void doGet(...) ... { ... }
    }

  • Problem with logout in servlet After logging out i need to expire the pages

    I have a problem in logout using servlet.
    I introduced sessions in my page and while logout i used
    session.removeAttribute("name");
    session.removeAttribute("password");
    res.setHeader("Cache-Control","no-store"); //Directs caches not to store the page under any circumstance
         res.setDateHeader("Expires", 0); //Causes the proxy cache to see the page as "stale"
         res.setHeader("Pragma","no-cache"); //HTTP 1.0 backward compatibility
    String user=(String)session.getAttribute("name");
              System.out.println(user);
              if(user==null)
                   System.out.println("hi");
                   req.setAttribute("Error", "Session has ended. Please login.");
                   res.sendRedirect("http://localhost:8080/homepage.html");
    and after i logout im redirected to login page but after clicking back button im getting back to restricted pages(the pages b4 logout).
    what should i do?????

    Thanks Dear BalusC,
    I tried with this,
    rs.getString("DATA_SCAD1")// where the source from .xls files
    String pattern = "yyyy-MM-dd";
    SimpleDateFormat format = new SimpleDateFormat(pattern);
    try {
    Date date = format.parse("DATA_SCAD1");
    System.out.println(date);
    } catch (ParseException e) {
    e.printStackTrace();
    System.out.println(format.format(new Date()));
    this out put gives me Tue Apr 03 00:00:00 IST 2007
    But I want to display the date format in yyyy-mm-dd.
    regards,
    maza

  • 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

  • Problem in compiling j2me file

    Hello friends,
    friends my problem in compiling j2me file..
    when i compile my j2me file through WTK2.2 (toolkit)
    then it creates extra file including j2me" .class" file..
    for example if my j2me file is "aman.java" and when i compile it
    then it will covert into "aman.class" file but it creates one more file like "aman1$.class" ..plz help me to get out of this problem..coz its increase my j2me file size..
    thanks
    Aman

    That is an inner class in aman.java that you are seeing there.
    If you use inner anonymous classes, for example;
    public class MyMIDlet extends MIDlet {
       // code for the MIDlet
       // Anonymous inner class
       setCommandListener(new CommandListener() {
          public void commandAction(Command c, Displayable d) {
            // implementation;
            // may access MyMIDlet's private fields
    }then the command listener you create will become another class named MyMIDlet$1.class.
    In this example you can get rid of the inner class by making one of the existing classes implement that CommandListener interface:
    public class MyMIDlet extends MIDlet implmements CommandListener {
       public void commandAction(Command c, Displayable d) {
         // implementation;
         // may access MyMIDlet's private fields
       // code for the MIDlet
       // Instead of the anonymous inner class, we can now use MyMIDlet since it
       // implements CommandListener
       setCommandListener(this);
       // etc. etc. etc.
    }shmoove

  • Problem in compiling with ant?

    Hi,
    I have problem with compiling using ant ..i have build file...and properly place directories.......
    C:/>ant build
    It's giving an error as "Exception in thread "main" java.lang.NoClassDefFoundError: build"
    can any one help me to solve this problem

    Cross-Post:
    http://forum.java.sun.com/thread.jspa?threadID=589924&tstart=0

  • Problem with compilation of HelloWorld.java

    hi,
    getting problem with compilation of HelloWorld.java
    CLASSPATH--- C:\java
    PATH--- C:\j2sdk1.4.2_04\bin
    HelloWorld.java source code in: C:\java
    On cmd prompt:
    C:\java>javac HelloWorld.java
    error: cannot read: HelloWorld.java
    1 error
    pls help me with this
    rgds,
    sanlearns

    What does this command yield?
    dir HelloWorld.java

  • Problem in running the servlet

    I have compiled the servlet and put the class file HelloWorld.class inside
    $CATALINA_HOME$/webapps/ROOT/WEB-INF/classes/
    directory, under tomcat6.0.18
    and also mapped servlet in
    $CATALINA_HOME$/webapps/ROOT/WEB-INF/web.xml, as below
    web.xml:
        <?xml version="1.0" encoding="ISO-8859-1"?>
    <!--
    Licensed to the Apache Software Foundation (ASF) under one or more
      contributor license agreements.  See the NOTICE file distributed with
      this work for additional information regarding copyright ownership.
      The ASF licenses this file to You under the Apache License, Version 2.0
      (the "License"); you may not use this file except in compliance with
      the License.  You may obtain a copy of the License at
          http://www.apache.org/licenses/LICENSE-2.0
      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.
    -->
    <web-app xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
       version="2.5">
      <display-name>Welcome to Tomcat</display-name>
      <description>
         Welcome to Tomcat
      </description>
      <servlet>
        <servlet-name>HelloWorld</servlet-name>
        <servlet-class>HelloWorld</servlet-class>
      </servlet>
      <servlet-mapping>
        <servlet-name>HelloWorld</servlet-name>
        <url-pattern>/HelloWorld</url-pattern>
      </servlet-mapping>
    </web-app>and run the servlet using this url......*.http://localhost/HelloWorld*
    but I got following error code under tomcat 6.0.18
      type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    javax.servlet.ServletException: Error allocating a servlet instance
         org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
         org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
         org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
         org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
         org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
         java.lang.Thread.run(Thread.java:619)
    root cause
    java.lang.NoClassDefFoundError: HelloWorld (wrong name: hall/HelloWorld)
         java.lang.ClassLoader.defineClass1(Native Method)
         java.lang.ClassLoader.defineClass(ClassLoader.java:620)
         java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
         org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1847)
         org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:890)
         org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1354)
         org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
         org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
         org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
         org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
         org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
         org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
         java.lang.Thread.run(Thread.java:619)
    note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs.is there something I did wrong?
    Edited by: san_4u on Mar 16, 2009 1:20 AM

    root cause
    java.lang.NoClassDefFoundError: HelloWorld (wrong name: hall/HelloWorld)Is your servlet contains first line as package hall;If it is there,remove it from the servlet code. And run your program.
    If you want to keep it, then make a folder named hall in classes folder and put your HelloWorld.class there. Also change <servlet-class> as
    <servlet>
        <servlet-name>HelloWorld</servlet-name>
        <servlet-class>hall.HelloWorld</servlet-class>
      </servlet>

Maybe you are looking for