How to access application vars into JavaBeans or Java File?

I have the application directory strcuture like this. I am using Apache Tomcat/6.0.14 and Eclipse IDE.
-/MyFirstServlet
-/MyFirstServlet/WebContent
-/MyFirstServlet/WebContent/WEB-INF/web.xml
-/MyFirstServlet/WebContent/web.jsp
-/MyFirstServlet/Src
     - com.model.DAO/userDAO.java (java class within package)
I have put following code into "web.xml".
==================================
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
     <display-name>
     MyFirstServlet
     </display-name>
     <context-param>
          <param-name>DBDriver</param-name>
          <param-value>com.microsoft.sqlserver.jdbc.SQLServerDriver</param-value>
     </context-param>
     <context-param>
          <param-name>connectionUrl</param-name>
<param-value>jdbc:sqlserver://localhost:1433;databaseName=MyFirstServletDB;user=hitesh;password=hit
esh;</param-value>
     </context-param>
     <welcome-file-list>
          <welcome-file>index.html</welcome-file>
          <welcome-file>index.htm</welcome-file>
          <welcome-file>index.jsp</welcome-file>          
          <welcome-file>default.jsp</welcome-file>
     </welcome-file-list>
</web-app>
I am easily able to access from "web.jsp"
===================================
String DBDriver = application.getInitParameter("DBDriver");
out.println("<br>DBDriver:==="+DBDriver);
String connectionUrl = application.getInitParameter("connectionUrl");
out.println("<br>connectionUrl:==="+connectionUrl);
BUT when I try to access withing userDAO.java it gives "application is not resolved"
========================================================================
String DBDriver = (String)application.getInitParameter("DBDriver");
NOTE: I understand I need to import some inbuilt java package which will allow to use applcation vars
within java class.
What is that package? and how to do that?
Is there any other easy method to use global/application vars which can be used in all
JSP/JavaBeans/Java files?
Thanks in advance.

It might be easier to put that code somewhere else. JSP's are for presentation, not for accessing databases, business logic, etc.

Similar Messages

  • How to access PPC contacts into my application using Flash

    Hi,
    I am new to flash lite anybody help me how to access PPC
    contacts into my application.

    Hi,
    I am new to flash lite anybody help me how to access PPC
    contacts into my application.

  • HT1491 How to access applications in AppStores other than that of my home country, as the apps i need are not available in home appstore

    How to access applications in AppStores other than that of my home country, as the apps i need are not available in home AppStore??!?

    What you want is Not possible...
    You must be within the Country with a Valid Billing Address and Credit Card for that Country to use the iTunes Store of that Country...

  • How  to divide an bytearray into chunks in java using streams

    how to divide an bytearray into chunks in java using streams

    i'm trying to read an image using fileinputstream then converting to bytearray after conversion i have to read that image chunk by chunk and write to a outputstream

  • How to view the change immediately after a java file is modified without restarting server or redeploy?

              Hi All,
              How to view the change immediately after a java file that is used in jsp is modified
              without restarting server or redeploy?
              Moreover, it is better to keep the original session.
              Any suggestion is appreciated.
              Kammau
              

              Hi,
              In order to have a new version of a java class, the current classloader must be
              deleted and a new one created. This is what redeployment does. I believe that
              this is more of an issue with Sun's implementation of classloaders. You could
              ask BEA support (719.232.7878) and see if they have any plans to periodically
              check jar files to see if java class file timestamps and destroy and re-create
              classloaders on the fly.
              1) You will still have to accept the performance hit of destroying classloaders
              and creating new ones. There isn't any way around that.
              2) I would think you would want to have more explicit control in production and
              integration anyway.
              You can redeploy applications from the command line (script) file not just the
              console.
              Hope this helps,
              pat
              "Kammau" <[email protected]> wrote:
              >
              >Hi All,
              >How to view the change immediately after a java file that is used in
              >jsp is modified
              >without restarting server or redeploy?
              >Moreover, it is better to keep the original session.
              >Any suggestion is appreciated.
              >
              >Kammau
              

  • How to access applications in another computer

    how to make use of java programs to access applications or files in another computer across the same network or over the internet. can help???

    how to make use of java programs to access
    applications or files in another computer across the
    same network or over the internet. can help???Overly broad question. Next!
    No seriously; what do you want ? Do you want to execute something (a process); do you want to execute it here, or there ? Do you want to connect to some service to do it for you ? Do you want the service to be distributed ? Do you want the service to maintain state ? Do you want to do it transparently inside your code, or do you want to explicitly implement a client API ?
    Your choices range from:
    - nfs or smb (execute here, executable there)
    - rsh or ssh (execute there, if the remote part is UNIX)
    - cgi over http (very common, but stateless)
    - CORBA or rmi (transparent remote OO calling)
    Read up on all these, and provide yourself with answers !

  • How to access application server 10g, if client machine is proxy settings.

    hi,
    i have installed oracle application server 10gR2, on vertual machine, windows2003
    my forms are stored in forms folder , i can access the application/forms
    throuhg client machines, if proxy setting is unchecked, but if proxy is chacked can't access application.
    as there with the user machine is required with proxy setting. how
    to access the application. i mean what is the configuration.
    in application server so that any computer (client machine)
    can access weather it is having proxy setting or not.

    now i enabled the java console to see the trace, there i found. if proxy is checked in client brouser with 8080 port which is required by organisation.
    Oracle JInitiator: Version 1.3.1.22
    Using JRE version 1.3.1.22-internal Java HotSpot(TM) Client VM
    User home directory = C:\Documents and Settings\fresh
    Proxy Configuration: Manual Configuration
    Proxy: eproxy:8080
    Proxy Overrides:
    Jar cache disabled by user
    c: clear console window
    f: finalize objects on finalization queue
    g: garbage collect
    h: display this help message
    l: dump classloader list
    m: print memory usage
    q: hide console
    s: dump system properties
    t: dump thread list
    x: clear classloader cache
    0-5: set trace level to <n>
    load: class oracle.forms.engine.Main not found.
    java.lang.ClassNotFoundException: java.io.IOException: open HTTP connection failed.
         at sun.applet.AppletClassLoader.getBytes(Unknown Source)
         at sun.applet.AppletClassLoader.access$100(Unknown Source)
         at sun.applet.AppletClassLoader$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at sun.applet.AppletClassLoader.findClass(Unknown Source)
         at sun.plugin.security.PluginClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadCode(Unknown Source)
         at sun.applet.AppletPanel.createApplet(Unknown Source)
         at sun.plugin.AppletViewer.createApplet(Unknown Source)
         at sun.applet.AppletPanel.runLoader(Unknown Source)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    Where as if there if i remove proxy setting by uncheck. then application goes smoothly.

  • How to access AM/VO instance from a Java Service class

    Hi,
    I have a Java service class that is loaded by Java ServiceLoader (http://download.oracle.com/javase/6/docs/api/java/util/ServiceLoader.html) at run time, and I need to access database tables inside that service class. So is there any way that I can access AM/VO instances from that Java class in order to read database table? Thanks.
    Regards,
    K Hein

    You can access an application module with the the two methods below:
        YOURAppModule mAM;
        public void setUpAM()
            throws NamingException
            try
                String AMDefName = "YOUR_APP_DEF_NAME";
                Hashtable env = new Hashtable(2);
                env.put(JboContext.INITIAL_CONTEXT_FACTORY, JboContext.JBO_CONTEXT_FACTORY);
                env.put(JboContext.DEPLOY_PLATFORM, JboContext.PLATFORM_LOCAL);
                ApplicationModule am = null;
                InitialContext ic = new InitialContext(env);
                ApplicationModuleHome home = (ApplicationModuleHome) ic.lookup(AMDefName);
                am = home.create();
                // Connect the AM to a database connection
                String jndiDB = "jdbc/HRDS";
                am.getTransaction().connectToDataSource(null, jndiDB, false);
                boolean connected = am.getTransaction().isConnected();
                mAM = (YOURAppModule) am;
            catch (NamingException nex)
                // do some error processing
                throw nex;
            catch (Exception eee)
                // do some error processing
                throw eee;
        public void tearDownAM()
            if (mAM != null)
                if (mAM .getTransaction().isConnected())
                    mAM .getTransaction().disconnect();
                    mAM .remove();
        }You find the YOUR_APP_DEF_NAME in your application module under 'Configurations' -> AppModuleJndiName.
    Make sure you tear down each AM you set up. Otherwise you are running out of resources pretty fast.
    Timo

  • How to access iPhone "Photo Library" to get image file properties?

    I want to access iPhone "Photo Library" to get image file properties(name, list etc..) without dialog.
    Is there any suitable method/class to this?

    Allan,
    Thank you for your reply!
    My purpose is access to "Photo Library" by iPhone API.
    Because, I know several iPhone application which has own image list and the list is synced to "Photo Library".
    If I take photo by iPhone native camera, the taken photo is listed up on the image list so I guess those applications can access to "Photo Library" directly.
    Or.. any other solution..?
    Gazza

  • How to access PL/SQL Web Services using java

    New to Webservices. Created PL/SQL Web Service using JDeveloper. Vendor is not sure how to access it using java. Can anyone please help to point in the right direction or provide some sample ?

    So if I'm correct you have already exposed a PL/SQL procedure or function as web service?
    In that case you can generate a proxy (client) for the generated web service using JDeveloper. It will generate Java code which invokes the web service.
    See the wizard in JDeveloper, it should be in the same category as the create PL/SQL web service wizard.
    Regards, Ronald

  • How to use schedule task for execute my java file

    I have five java file.
    I want every 20 minutes all of them executed.
    how to write the program for scheduling that execution.

    > I have five java file.
    I want every 20 minutes all of them executed.
    how to write the program for scheduling that
    execution.
    I recommend using an external application (e.g., Task Scheduler, cron, etc.) to handle this kind of scheduling.
    ~

  • How to count number of methods in a java file

    Is there any way to know the count of methods or variables (instance) in a java file or at least in main() of a java file?
    If yes , can we know about their access modifiers?

    raj440 wrote:
    Is there any way to know the count of methods or variables (instance) in a java file or at least in main() of a java file?
    If yes , can we know about their access modifiers? It might be easier to use Reflection to interrogate the class itself instead of the source.
    A "variables (instance)" is somewhat of an oxymoron.

  • How to mention a  Relative path in a java file

    How to mention the relative path of the file in fileinputstream?
    The directory structure is as follows,Inside the **model** folder i have a java file called GetContents.java
    I need to refer the input.xls file inside the template folder in GetContents.java.file.
    I tried new FileInputStream("..\\..\\..\\template\\DevContentsTemplate.xls") cos the GetContents.class file will be inside webcontent\web-inf\classes\model\GetContents.class and I thought if i use the above relative path , it should refer webcontent\web-inf\template\input.xls
    But it throws a file not found exception.
    ContentValidation
    - src
    -action
    -model
              -bean
              -form
              -utils
    -WebContent
                   -WEB-INF
                        -classes
                        -action
                   -model
                             -bean
                             -form
                             -utils
                        -lib
                   -template
                             -input.xls
    Kindly help.
    Thanks.

    morshed_nsu wrote:
    if so then for one ../ you will reach classes folder. for another you will reach the folder containing src, classes, templates etc.
    So you do not need 3 escapes.I posted that same answer 7 hours before you did! What part of your answer is any additional help compared to mine? It's fine to give someone another answer, but there's not much point in giving the SAME answer 7 hours later. If it were a few seconds or a few minutes later, I would excuse you for having tried to post at the same time. But, 7 hours?! Please read the existing answers next time, not just the original post.

  • How can I build EJB archive after changing java files?

    hello,
    I changed java beans file, and tried to build jar file again, then the "build EJB archive" context menu is disabled so I can not make EJB jar file!
    So frustrated.. NWDS recognizes the changes in the java files , right? How come there 's no Build menu..
    Is there any pre-requisite to enable the menu?
    I have no idea how I can build jar file..
    Please give me a advice.. Thanks~!

    I think that in order to create a RPM, you'd need to
    use some C.Nope - the RPM is all about packaging and the "magic" x.spec file. You can have anything you want in the RPM, but you have to use RPM tools to build the .rpm file. One of the features is that you can also indicate (via "install" scripts) modifications to other files or the filesystem to support the installation of whatever's in the RPM.

  • How to make a "Program" out of my .java files?

    I have made a little application that stores a file to disk. Is there someway to make a file out of my .java files so it can be run without opening my editor and choosing run?

    sorry I didn't check that, I can now run the jar command.
    But even though I can create a .jar file I get an error. I have followed the guide that says I need to add the applications Entry point.
    I have two classes:
    saveDates.class //contains the main method
    UserInput.claa // Parsing of user input
    When I create the jar file I type:
    jar cfe saveDates.jar SaveDates SaveDates.class UserInput.class
    But when I try to run it like:
    java -jar saveDates.jar
    I get the error:
    C:\workspace\dato>java -jar saveDates.jar
    Exception in thread "main" java.lang.NoClassDefFoundError: SaveDates$1
    at SaveDates.main(SaveDates.java:89)
    C:\workspace\dato>
    Do I need to change the main method someway?

Maybe you are looking for

  • I keep getting this error code 7 (windows error 126).  can't open itunes, what do i do?

    i keep getting this error code 7 (windows error 126).  can't open itunes, what do i do?

  • Data entry in the table

    Hi All, I havae a scenario.. I have one ztable with the foloowing fields: 1. enum 2. Ecnum 3. Add 4. Date 5. erole what I did is I made enum and ecnum fields as the key fields in the table and rest I didn't make as key fields. Now when I tried to ent

  • Rendered video very low quality

    My camera shoots in MTS format. I converted the file to mp4 and edited it. I then imported that footage into After Effects and when I tried to render the video it was very low quality. I made sure the composition settings and render settings matched

  • Formats in table

    hi there! i'm trying to create a table in jsp with data from a database table. the database table values are: varchar2 - varchar2 - integer - integer - varchar2. the connection etc seems to work fine because the two first varchars show on the jsp pag

  • Cisco Prime 1.2 device interface alarms

    Hello All, I am working on Cisco Prime Infrastructure 1.2.1.012. I have enabled prime to report interface up and down messages. But I am seeing some strange messages such as below, Alarm Condition:Link down Message: Port '{0}' is up on device '{1}'.