Once i set classpath to servlet-api.jar, it doesnt Instantiate DbBean.

I am using notepad editor. I am trying to instantiate a DbBean class inside the servlet's init() method.
once i set (C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\servlet-api.jar) this path to compile the Controller servlet.
C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\ROOT\WEB-INF\classes>set classpath=C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\servlet-api.jar
C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\ROOT\WEB-INF\classes>javac Controller.java
Controller.java:5: package bean does not exist
import bean.DbBean;
^
Controller.java:14: cannot find symbol
symbol : class DbBean
location: class Controller
DbBean dbbean = new DbBean();
^
Controller.java:14: cannot find symbol
symbol : class DbBean
location: class Controller
DbBean dbbean = new DbBean();
^
3 errors
C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\ROOT\WEB-INF\classes>
this is my servlet
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import bean.DbBean;
public class Controller extends HttpServlet
public void init(ServletConfig config)throws ServletException
ServletContext context = config.getServletContext();
context.setAttribute("base_url",config.getInitParameter("base_url"));
{color:#ff0000}DbBean dbbean = new DbBean();{color} {color:#0000ff}error showing in this line
{color}dbbean.setDburl(config.getInitParameter("dburl"));
dbbean.setUserName(config.getInitParameter("username"));
dbbean.setPassward(config.getInitParameter("pwd"));
/// database bean can be access from jsp page
context.setAttribute("dbbean",dbbean);
/// Load the data base driver
try{
Class.forName(config.getInitParameter("jdbcDriver"));
catch(ClassNotFoundException e)
System.out.println(e.toString());
super.init(config);
public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException,IOException
doPost(req,res);
public void doPost(HttpServletRequest req, HttpServletResponse res)throws ServletException,IOException
String base = "/onlinetest1/";
String url = base + "login.jsp";
String action = req.getParameter("action");
if(action!=null)
if(action.equals("successlogin.jsp"));
url = base + "successlogin.jsp";
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url);
dispatcher.forward(req,res);
public void destroy()
System.out.println("Servlet stopped");
This below class can be put inside bean folder( (ie)sub dir of controller servlet)
package bean;
import java.sql.*;
import java.util.*;
import java.io.*;
public class DbBean
String dburl="";
String dbuser="";
String dbpass="";
public void setDburl(String url)
dburl = url;
public void setUserName(String uname)
dbuser = uname;
public void setPassward(String pwd)
dbpass = pwd;
What to do to rectify this, please help me why this error coming,

hi,
Actually i did my ordinary package compilation example below, its run correctly, but after set classpath to %tomcat-home%\common\lib\servlet-api.jar(for same programs its not working) this kinds of error coming.
F:\shyam\test>javac first.java
F:\shyam\test>java first
main class
DB Set Correctly
F:\shyam\test>set classpath=C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\servlet-api.jar
F:\shyam\test>javac first.java
first.java:1: package bean does not exist
import bean.DbBean;
^
first.java:10: cannot find symbol
symbol : class DbBean
location: class first
DbBean dbbean = new DbBean();
^
first.java:10: cannot find symbol
symbol : class DbBean
location: class first
DbBean dbbean = new DbBean();
^
3 errors
F:\shyam\test>
In compilation it wont take DbBean class, please help me.
thanks in advance,
S.Shyam

Similar Messages

  • I FOUND : servlet-api.jar ...WHERE insert it to can compile SERVLETS

    I FOUND : servlet-api.jar in TOMCAT 6
    WHERE insert it to can compile SERVLETS ?
    where added(directory), some folders follow...?
    C:\Program Files\Java\jdk1.6.0_15\bin
    C:\Sun\AppServer\lib
    C:\Program Files\Java\jdk1.6.0_15\src\javax

    You can use any of the following methods:
    i) SET CLASSPATH variable with absolute path of your servlet-api.jar and then compile your servlet from any folder.
    ii)you can use
    C:\jdk\bin>javac -cp C:\tomcat\lib\servlet-api.jar SampleServlet.javaand after comilation put the compiled java class file to classes folder of you web application.
    [Obviously if you have any package, then you need to maintaing that folder structure inside classes folder]
    Here I assumed your javac is available at C:\jdk\bin folder and servlet-api.jar is available at C:\tomcat\lib folder
    ---Sujoy

  • I need to install servlet-api.jar in the libext folder.

    Hi I am doing a tutorial on struts 2.0.11.
    i need to install servlet-api.jar in the libext folder which I have created inside WEB-INF
    Now I have downloaded servlet.api which is in the zip form.
    When I extract the files. Its giving me two folders
    1. javax
    2. META-INF
    Inside javax there is a folder called servlet. Inside servlet folder there are
    a) bunch of call files
    b) http folder
    c) resources folder
    Inside http folder there are
    a) class files
    b) properties files
    Inside the resources folder there are
    a) dtd files
    b) xsd files
    Inside the META-INF folder there is the manifest.mf file
    I just need servlet-api.jar
    I think that I have extracted the contents of servlet-api.jar by using the extract feature of winzip.
    Do you think that by just changing the extension of the file from servlet-api.zip to servlet-api.jar it will do the trick or do i need to do something else.
    Please guide

    pksingh79 wrote:
    Hi ^^,
    your replies were very helpful. I did try to check the lib folder of the webserver and there was not servlet-api.jar. However I downloaded a dummy project and it did have servlet-api.jar in it, so I am ok for now.
    thanks and regards,
    PrashantYou should not be doing that. Always use the one from the application server which you're going to use. Otherwise you will possibly get in runtime trouble due to version differences.
    The actual location and filename of the servlet API might differ per application server implementation. If it was for example Tomcat 6, it is the servlet-api.jar in the /lib directory. If it was for example Glassfish (the current release), then it is the javaee.jar in the /lib directory.

  • How to Set Classpath in servlet

    Hi Friends,
    I want to call class with using reflection in my "servlet" , since class which I am calling is stand alone java program and it is not in web application. It is stored else where on server in Offline process. So how can I call the method of this class from my Servlet.
    Reply is appreciated

    any server when it starts up, loads the classes and lib from specifed paths in a config file.
    e.g., jrun has a jvm.config file where you can give the classpath entries for third party classes/jars.
    also for the specific classpath entry for particular war-file, u can specify it in the manifest-file of the war.

  • Setting CLASSPATH wthin a runnable Jar

    OK bear with me here, I'm not a total newbie.. really! I've built executable jars before, but with just the directories of raw classes inside.
    Now, I want to package up some jars, and point the classpath at these.
    So in my Ant build file I have
        <jar jarfile="CSVConverter.jar" basedir="." excludes="cvs CSVConverter.jar *.xml *.pdf *.xls *.bat">
           <manifest>
              <attribute name="Main-Class" value="CSVConverter"/>
              <attribute name="Class-Path" value=".;fclui.jar;dom4j.jar;fop.jar;avalon-framework-4.1.5.jar"/>
           </manifest>
        </jar>I added the "." to the claspath because it wasn't finding the Main Class. That seems wrong for a start!
    But it also can't find classes in the specified jars which ARE in the jar file, Ant tells me it's adding them, and I've checked.
    FYI, the error message is
    Exception in thread "main" java.lang.NoClassDefFoundError: com/fcl/xmlutils/CSVXMLReader$CSVSourceAnd that is in fclui.jar which is in the main jar: CSVConverter.jar.
    In case anyone is curious, it's a tool to use a SAX parser to create XML parse events from a CSV document, use XSL to massage the document into either the correct XML format for Excel (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnexcl2k2/html/odc_xmlss.asp), or FOP (http://xml.apache.org/fop/), and through fop to PDF. Basically the top line of the CSV is headers, subsequent lines are data, and out comes a very nicely formatted, and scaled report either Excel or PDF.

    The Class-Path is used as a hint to browsers to so
    they can down load additional JARs before they are
    called.
    This attribute is not use by java and the claspath
    cannot be set this way.Sorry, but this is just plain wrong!
    Please see http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#JAR%20Manifest
    "Class-Path :
    The value of this attribute specifies the relative URLs of the extensions or libraries that this application or extension needs. URLs are separated by one or more spaces. The application or extension class loader uses the value of this attribute to construct its internal search path."
    Still, JARs in a JAR will not work, AFAIK ...

  • Compiling servet.error wrong version of servet-api.jar

    hi,
    I try to compile the following servlet
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class ServletTemplate extends HttpServlet
         public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
              PrintWriter out=response.getWriter();
    But I got the follwing error.
    D:\apache-tomcat-6.0.14\webapps\Raju\WEB-INF\classes>javac SevletTemplate.java
    SevletTemplate.java:5: class ServletTemplate is public, should be declared in a
    file named ServletTemplate.java
    public class ServletTemplate extends HttpServlet
    ^
    SevletTemplate.java:5: cannot access javax.servlet.http.HttpServlet
    bad class file: D:\apache-tomcat-6.0.14\lib\servlet-api.jar(javax/servlet/http/H
    ttpServlet.class)
    class file has wrong version 49.0, should be 48.0
    Please remove or make sure it appears in the correct subdirectory of the classpa
    th.
    public class ServletTemplate extends HttpServlet
    ^
    2 errors
    I have set CLASSPATH with servelt-api.jar.
    Please help me

    rajuchinu wrote:
    class file has wrong version 49.0, should be 48.0You have compiled it with a newer javac version than the JRE version with which you're running it.
    Check java -version and javac -version and align them both out to the same version.

  • How to  set the classpath for servlet and jsp???

    i add C:\tomcat-5.0\common\lib\servlet-api+jsp-api to the class path from DOS prompt, as show below:
    set CLASSPATH=%classpath%;C:\tomcat-5.0\common\lib\servlet-api.jar;C:\tomcat-5.0\common\lib\jsp-api.jar
    then, i compile the servlet:
    javac FirstServlet.java
    no error
    and i copy the .class file into C:\tomcat-5.0\webapps\servlets-examples\WEB-INF\classes
    i set the JAVA_HOME enviroment variable as below:
    set JAVA_HOME=C:\Program Files\Java\jdk1.5.0_08
    i start the tomcat version 5.0 and run web browser and type http://localhost:8080/servlets-examples/servlet/FirstServlet
    i get the error message:
    HTTP Status 404 - /servlets-examples/servlet/FirstServlet
    type Status report
    message /servlets-examples/servlet/FirstServlet
    description The requested resource (/servlets-examples/servlet/FirstServlet) is not available.
    Apache Tomcat/5.0.30
    Can anybody tell me how to solve the problem. Thanks a lot.

    You will have to create the servlet mapping in the Web.xml file
    <servlet>
                 <servlet-name>FirstServlet</servlet-name>
                 <servlet-class>FirstServlet</servlet-class>
        </servlet>
    <servlet-mapping>
            <servlet-name>FirstServlet</servlet-name>
            <url-pattern>/servlet/FirstServlet</url-pattern>
        </servlet-mapping>

  • Setting classpath to execute jar file.

    I have dependency jar files to execute my jar file.
    set classpath=./lib/tpc.jar;./lib/jxl.jar;
          ./lib/log4j-1.2.15.jar;./lib/logSys.jar;
    java -jar ./lib/tpc.jar %1java -jar seems not taking classpath environment variables and showing error as
    Exception in thread "main" java.lang.NoClassDefFoundError:
    com/sys/logger/LogManager
            at utility.tpc.generate.Tpc.generate(Unknown Source)
            at utility.tpc.generate.Tpc.main(Unknown Source)The below one works, but I dont want to give all jar files along with java command and to make complicate.
    java -cp "./lib/tpc.jar;./lib/jxl.jar;./lib/log4j-1.2.15.jar;./lib/logSys.jar;"
             utility.tpc.generate.Tpc %1Is there a way to make first one to work ? Will adding "Class-Path:jxl.jar,log4j-1.2.15.jar,logSys.jar" in my manifest file make it work ?

    baskark wrote:
    I have dependency jar files to execute my jar file.
    set classpath=./lib/tpc.jar;./lib/jxl.jar;
    ./lib/log4j-1.2.15.jar;./lib/logSys.jar;
    java -jar ./lib/tpc.jar %1java -jar seems not taking classpath environment variables and showing error as
    Exception in thread "main" java.lang.NoClassDefFoundError:
    com/sys/logger/LogManager
    at utility.tpc.generate.Tpc.generate(Unknown Source)
    at utility.tpc.generate.Tpc.main(Unknown Source)The below one works, but I dont want to give all jar files along with java command and to make complicate.
    java -cp "./lib/tpc.jar;./lib/jxl.jar;./lib/log4j-1.2.15.jar;./lib/logSys.jar;"
    utility.tpc.generate.Tpc %1Is there a way to make first one to work ? Will adding "Class-Path:jxl.jar,log4j-1.2.15.jar,logSys.jar" in my manifest file make it work ?The jar command is specified to work as you have shown. That is, when you use "java -jar..." the system or command line classpath is ignored. The only classpath that can be used with "java -jar..." is the Class-Path in the manifest. You need to separate the different paths using space characters, not ; or : and the paths need to be relative to the jar file. (I am not sure if "./" will work and it is not needed to specify relative to the jar file.)
    Edited by: atmguy on Dec 14, 2009 8:42 AM

  • Setting Classpath in linux

    Hi !! Can anyone help me in setting classpath in linux to run servlets/? I tried using this command..but didnt work
    export CLASSPATH="$CLASSPATH:/usr/share/tomcat5/server/lib/servlets-common.jar"
    Thanks
    Nive

    in ur autoexec.bat file write the following
    set PATH=C:\jdk1.5.0_04\bin;%PATH%
    set JAVA_HOME=C:\jdk1.5.0_04
    set
    CLASSPATH=.;C:\jakarta-tomcat-5.5.9\common\lib\servlet
    -api.jar;C:\jakarta-tomcat-5.5.9\common\lib\jsp-api.ja
    r;C:\Servlets+JSP;..;..\..;C:\jakarta-struts-1.2.4\lib
    \struts.jarThis response is meaningless. Principally because the OP specifically mentioned the use of LINUX. Not Windows.
    I've taken the advice of other forum users by avoiding a system level classpath variable. I define the classpath each time I compile and run. Working on Linux I tend to use command line argument files ( http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/javac.html#commandlineargfile ) which eliminates the need to redefine the classpath each time I compile or run my classes and apps. But others may do things differently.
    Here is a website you might want to check out which pertains to setting the classpath on Solaris and Linux.
    http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/classpath.html

  • Problems setting classpath...

    hello guys...i am having a problem with what should be a very simple operation...
    the classes i define are stored in the classes directory..inside, each package has its own subdirectory...
    classes
    beans
    User.class
    Cart.class
    i have tried to change my classpath to reflect this location and instruct the compiler as to where to find those classes..
    i have used the set Classpath command...
    SET CLASSPATH=.;C:\Tomcat\common\lib\servlet-api.jar;C:\Tomcat\common\lib\mysql-connector-java-3.1.13-bin.jar;
    C:\Tomcat\webapps\theagent\WEB-INF\classes beans.User;
    but when i try to import beans.User in another class..it doesnt compile and tells me that the package doesnt exist...
    please help....what else do i need to check to make sure the configuration is as it should be...
    p.c User.java started with package beans;
    thanks

    That is correct because your beans.User class doesn't contain a
    public static void main(String[] args) method, iow you can't run it by itself.i dont want to run the class by itself... i just want to import beans.User;
    but it says that no such package exists...Then you have to be a bit more clear. You mentioned this command line:java -classpath C:\Tomcat\common\lib\servlet-api.jar;
    C:\Tomcat\common\lib\mysql-connector-java-3.1.13-bin.jar;
    C:\Tomcat\webapps\theagent\WEB-INF\classes beans.User;This sets the classpath pointing to two jars and a 'classes' directory.
    You're trying to run the 'beans.User' class which I presume is stored
    in a subdirectory of that 'classes' directory.
    The java command works like this:java -classpath <jars and dirs here> package.YourClass... so you were trying to run your beans.User class all by itself. It doesn't
    contain a main method hence the runtime diagnostic. btw, I don't know
    why you appeded that whole thing with a semicolon.
    kind regards,
    Jos

  • Servlet-jsp.jar file

    Hi
    iam new to use jstl.i wrote on tag handler (java) class when i am compiling it is not identifying any of javax.jspexception ,java.jsp.tagext.
    please help me what are all the jar files i have to have in class path or at any place and from where can i download them. i searched for servlet-jsp.jar,servlet-api.jar but i could not find anywhere in java.sun.com.any help is greatly appreciated
    thanks

    hi thanks for the reply. iam using tomcat 5.0
    server. from where can i down load those jar files
    please let me know
    what jar files are needed if iam using tomcat 5.0 Like I said, Tomcat 5 uses Tomcat 5: servlet-api.jar jsp-api.jar. They will be in the server's classpath someplace. Look around were you installed TC. I am away from my machine at the moment so I can't say for sure, but it might be common/lib or shared/lib, something like that...
    and
    if weblogic 8.0Dunno. Look around the file structure.
    Thanks for the help

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

  • Missing artifact javax.servlet.jsp:jsp.api:jar:2.1 Eclipse error

    When I try to UPDATE my Maven project ( Chapter 8 - Using JSP with AEM 6.0 ) after I updated my main pom.xml with the javax.servlet.jsp dependancy, I get the following error :Missing artifact javax.servlet.jsp:jsp.api:jar:2.1
    I even tried to compile from command line using mvn compile and get the same error :
    [ERROR] Failed to execute goal on project company-training-project-bundle: Could  not resolve dependencies for project com.adobe.training:company-training-project-bundle:bundle:1.0-SNAPSHOT:
    Could not find artifact javax.servlet.jsp:jsp.api:jar:2.1 in adobe (http://repo.adobe.com/nexus/content/groups/public/) -> [Help 1]
    If I look at my .m2 dir, I can see that it attempted to get the jar, but it wasn't able to grab it :

    Hi Billy,
    Try changing the URL from (http://repo.adobe.com/nexus/content/groups/public/) to (https://repo.adobe.com/nexus/content/groups/public/), i.e. add the https.
    That should do it. Let us know if it doesn't work.

  • Setting session timeout in servlet API 2.0 - based JSP (Apache/JServ)

    I'm using Apache/JServ (servlet API 2.0) to run JSPs. At present, a session becomes invalid after 30 minutes of inactivity. How can I increase or decrease this time?
    Thanks.

    You can set by using this command in JSP or servlet
    session.setMaxInactiveInterval(1800);
    replace 1800 (this is in seconds) with the number you want
    Suresh

  • How to use jar files without setting classpath

    Hi,
    I have a situvation, I can not set classpath, but i have to use jar files, how can I do that.

    URL[] urls = new URL[]{pathToJar, pathToAnotherJar, ...};
    URLClassLoader urlc = new URLClassLoader(urls);
    Now load classes within the jars loaded by the urlc classloader as needed. This is a limited approach, you can mostly use interfaces to work with classes loaded by the custom loader instance above and your existing classes.

Maybe you are looking for

  • One iTunes account two passwords

    I have 1 iTunes account (user iD), but have two passwords for some reason (I have one main password for most apps, but several apps are using an older password).  The result is I have to authorize my PC twice for one account.  Is there anyway I can m

  • Since installing Firefox, my number pad on my laptop & my Cannon printer don't work

    Acer aspire5742 G using Window 7 Cannon printer MX880 series - whether in wifi mode or plugged in to pc get message printer off line. All plug in properly new cartridges put in properly but cartridge lights are shining. Thanks Roseskick

  • Does the Intel 82579LM NIC on the Portege R830 support Promiscuous mode?

    Hi, I've got a work laptop (Portege R830), which doesn't want to sniff packets. I've got it connected to a Netgear Hub (DS104), along with an older notebook, and then uplink to ADSL. Running a continuous ping to the default gateway and Wireshark on b

  • File Adpater

    I'm a beginner in BPEL so excuse the little knowledge I have. I am trying to write to a file using a file adapter. I want to use the BPEL process to take messages and update the file using the adapter. I am configurig the file Adapter. I have located

  • Trouble loading webpage in safari ... Blank Image

    A friend of mine send me an webpage he has been working on and for some reason it will not load in Safari. I have been through the code, renamed, and deleted to no avail. The page loads fine in Firefox. The only thing that I can figure out is that if