Reading a global variable from tomcat with JNDI. Example not working

Hi you can help me to make this example work?
Context initCtx = new InitialContext();
Context envCtx = (Context)initCtx.lookup("java:comp/env");
Object o = envCtx.lookup("testvariable");
<GlobalNamingResources>
<Environment name="testvariable" type="java.lang.Boolean" value="false"/>
Nice greetings Christian

I found out that in addition to having the JNDI lookup code, you have to
- have the environment variable declared in the app server configuration
- have a resource-env-ref entry in your webapp module
- have the application container bind your named variable with the global variable
I am using tomcat 5.5, and have done the following. with success.
the following example uses the default sample environment variable in the tomcat server.xml
in tomcat server.xml:
<GlobalNamingResources>
<Environment
name="simpleValue"
type="java.lang.Integer"
value="30"/>
</GlobalNamingResources>
in my application's web.xml:
<resource-env-ref>
<description>Test read resource environment variable</description>
<resource-env-ref-name>simpleValue</resource-env-ref-name>
<resource-env-ref-type>java.lang.Integer</resource-env-ref-type>
</resource-env-ref>
in my META-INF/context.xml (or otherwise, in tomcat's context deployment configuration)
<ResourceLink name="simpleValue" global="simpleValue"
type="java.lang.Integer"/>
Note: in theory, the named resource by your web app could be different from the global environment variable, but here they are the same 'simpleValue'
This is the really important step, that with out it, nothing works.,
the context.xml is known to work with tomcat when it exists in META-INF/context.xml inside the .war file (i use war files to deploy, but you should be able to create META-INF/context in an unpacked webapp directory too, and tomcat will find it.,
I can not say what it is like for other app servers, but this mapping step is the critical point that i discovered after A LOT of hair pulling.
then, make use of it, i created a jndiTest.jsp:
<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="javax.naming.NamingException" %>
<%
try {
Context initCtx = new InitialContext();
Context ctx = (Context) initCtx.lookup("java:/comp/env");
Object o = ctx.lookup("simpleValue");
%>
<%=o%><br>
<%
catch (NamingException ex) {
System.err.println(ex);
%>
since my server.xml defines the value for 'simpleValue' to be 30, this page displays 30

Similar Messages

  • Do you know how to get Tomcat's JNDI example to work? - Help!

    With regards to the example for JNDI Datasource How-To found on Apache's site at http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html
    I did the example as they explained to. But I keep getting "foo - not connected" when I run the "test.jsp" page on my Tomcat server.
    I made the following changes to the example
    1) don't know if this bears any importance, but I've changed wherever it says "TestDB" to "DBTest"
    2) I changed the portion in bold text in this parameter ---
    <parameter>
    <name>url</name>
    <value>jdbc:mysql://localhost:3306/javatest?autoReconnect=true</value>
    </parameter>
    in the server.xml file to localhost:8080 as this is my port # for the tomcat server.
    3) they had the <value> attribute set to org.gjt.mm.mysql.Driver so I changed it to the following...was this incorrect for me to do?
    <parameter>
    <name>driverClassName</name>
    <value>com.mysql.jdbc.Driver</value>
    </parameter>
    Questions and noticeable problems
    1) I'm getting a **END NESTED EXCEPTION ** Attempted reconnect 3 times. Giving up.
    at com.mysql.jdbc.Connection.createNewIO(Connection.java:1780)
    at com.mysql.jdbc.Connection.<init>(Connection.java:427)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:395)
    and the list continues (this is in the dos-prompt window that pops up after starting Tomcat). Unforntunately I'm unable to copy and paste it all into this forum. It also has lines similar to above relating to org.apache.commons.dbcp.DriverConnectionFactory etc.
    2)What am I doing wrong? I really want to get this to work....I'm hoping to eventually learn and apply connection pooling to an application....
    3) is there something somewhere that I'm not "configuring" properly?
    Ask me for any information pertinent to this problem I'm having, and I'll try to post a reply with whatever is requested.
    can anybody help me out??

    With regards to the example for JNDI Datasource How-To
    found on Apache's site at
    http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-da
    asource-examples-howto.html
    I did the example as they explained to. But I keep
    getting "foo - not connected" when I run the
    "test.jsp" page on my Tomcat server.
    I made the following changes to the
    example
    1) don't know if this bears any importance, but I've
    changed wherever it says "TestDB" to "DBTest"This ought to reflect the name of the database you're connecting to in MySQL.
    >
    2) I changed the portion in bold text in this
    parameter ---
    <parameter>
    <name>url</name>
    <value>jdbc:mysql://localhost:3306/javatest?auto
    econnect=true</value>
    </parameter>
    in the server.xml file to localhost:8080 as
    this is my port # for the tomcat server.No, the port number in this case should be the one that the database listener is attached to, not the Tomcat server. Think about what this is doing: it's setting up the database URL, not the Tomcat listener.
    >
    3) they had the <value> attribute set to
    org.gjt.mm.mysql.Driver so I changed it to the
    following...was this incorrect for me to do?
    <parameter>
    <name>driverClassName</name>
    <value>com.mysql.jdbc.Driver</value>
    </parameter>That looks like the name of the MySQL JDBC driver class.
    >
    Questions and noticeable problems
    1) I'm getting a **END NESTED EXCEPTION **
    Attempted reconnect 3 times. Giving up.
    at
    com.mysql.jdbc.Connection.createNewIO(Connection.java:1
    80)
    at
    com.mysql.jdbc.Connection.<init>(Connection.java:427)
    at
    com.mysql.jdbc.NonRegisteringDriver.connect(NonRegister
    ngDriver.java:395)
    and the list continues (this is in the dos-prompt
    window that pops up after starting Tomcat).
    Unforntunately I'm unable to copy and paste it all
    into this forum. It also has lines similar to above
    relating to
    org.apache.commons.dbcp.DriverConnectionFactory etc.
    2)What am I doing wrong? I really want to get this to
    work....I'm hoping to eventually learn and apply
    connection pooling to an application....
    3) is there something somewhere that I'm not
    "configuring" properly?
    Ask me for any information pertinent to this problem
    I'm having, and I'll try to post a reply with whatever
    is requested.
    can anybody help me out??Did you put the MySQL JDBC JARs in your WEB-INF/lib? How 'bout the database connection pool JAR?
    This works. If it's not happening, that means you're doing something wrong. The good news is that you'll find it eventually if you keep digging.

  • Java Applet HelloWorld "Getting Started With Applets" example not working

    Hi there,
    It's been ages since I ran my Linux CentOS boot of Linux but I am going through the official oracle java applet tutorials, just every time I try and run the "Hello World" applet in Firefox 17.0.3 and I am running the Iced Tea thing for java applets.
    Every time I try and run the example from the following code:
    import javax.swing.JApplet;
    import javax.swing.SwingUtilities;
    import javax.swing.JLabel;
    public class HelloWorld extends JApplet
      // called when the user enters the html page:
      public void init() // keep apps within the init() function very small as per the http://docs.oracle.com/javase/tutorial/deployment/applet/appletMethods.html
        try{
          SwingUtilities.invokeAndWait(new Runnable()
            public void run()
           JLabel myLabel = new JLabel("Hello World");
           add(myLabel);
            } // end running the application
          }); //end of swing invokeand wait
        } catch (Exception error){ // end user running the app in page
           // System.err.println("GUI didn't work on initial run");
    }It keeps bringing up the error "Start: Applet not initialized" I did google that basic error and from what I found I should consult the JavaConsole, I know the console was removed from the Firefox menu quite a while ago. So went to find a way of loading it using the IcedTea one but it keeps bringing up a load of errors in even trying to run that.
    Is there anyway of sorting this out? I mean I have even tried installing the one on the oracle website, the plain JDK but nothing seems to work.
    Is there anyone that can help me get applets working? I was even going to go as far as to reinstall my distro but I want to avoid that as much as possible.
    Thanks and I look forward to any replies,
    Jeremy.

    in the Getting Started with Java DB tutorial they
    tell u how to set ur "DERBY_HOME" (what is that?).
    once i press enter after typing this command:
    set DERBY_HOME=D:\Java\Java
    Phonebook\javadb in my command prompt do i get
    any message or does it just go to the next line?type env or set or whatever in the command line to see what your environment variables are set to
    they also tell u how to set ur "JAVA_HOME" (what is
    that?). The Java installation you want to use
    in their example they give u this: set
    JAVA_HOME=C:\Program Files\Java\j2se1.4.2_05but in my java folder i have jdk1.6.0 and jre1.6.0
    but no j2se1.4.2_05, so which 1 must i choose?It's up to you. I'd go with 1.6
    also once ive done this: set
    DERBY_HOME=D:\Java\Java Phonebook\javadb this
    set JAVA_HOME=D:\Program
    Files\Java\jre1.6.0 and this set
    PATH=%DERBY_HOME%\bin;%PATH% and then type
    sysinfo to verify that the variables were set
    correctly i get these errors: 'D:\Java\Java' is
    not recognized as an internal or external command,
    operable program or batch file and '""'
    is not recognized as an internal or external command,
    operable program or batch file any help would
    really be appreciated because this is really killing
    me!you need to set your path variable - so something like:
    set PATH=C:\Program Files\Java\j2se1.4.2_05\bin

  • Is it possible to read Essbase Substitution variables from ODI?

    Is it possible to read Essbase Substitution variables from ODI?

    Hi,
    You can do it with custom code, if you have a read of a blog I wrote :- http://john-goodwin.blogspot.com/2009/11/odi-series-planning-11113-enhancements.html
    About half way through I go into reading essbase sub vars using the essbase java API.
    Cheers
    John
    http://john-goodwin.blogspot.com/

  • StringTokenizer to read in 4 variables from the command point

    Hi,
    I need to set up the Java StringTokenizer to read in 4 variables
    from a command prompt. It should be in the following format:
    X variable1 variable2 variable3where
    (is the command prompt)X (is either +, -, *, /, c, or e)
    variable1 variable2 and variable3 are integers.
    I would appreciate any answers that would help me find the way!
    Thanks in advance.

    Thank you for the code snippet, but the program does not function that way. Ie, it does not accept
    arguments when the program is first run, only after the program has excecuted.
    The program is to enter a simple command prompt, and await instructions in the form X int1 int2 int3
    where X can be c (convert the number int3 from number base int1 to number base int2), e (exit the
    program), +,-,/,* (add, subtract, divide or mutilply int2 to/by int3 in number base int1). Here is an example
    of the what the program execution should look like:
    c:\programming\java nbc
    > + 10 23 45 // Add 23+45 in base10
    68 // Write the answer on a new line and prompt
    - 16 5A 2C // Subtract 5A-2C in base 162E // Write the answer on a new line and prompt
    c 15 7 2E // Convert 2E in base 15 to base 762
    e // End of programc:\programming\
    My problem is, I do not know how to convert the first token to a variable that can be used to carry out one of
    the above mentioned procedures. For example, the first token taken from the command c 15 7 2E is "c".
    As I understand it, "c" is simply a string, and this cannot be used in logical procedures such as:
    int procedure = 0;
    if(operator == "c")
         procedure = 0;  //then use this variable
    }else
    if(operator == "e")
        System.exit(0): //quit the program
    Also, how can I set up a while loop to continuesly
    prompt the user for an instruction until "e" is entered?import java.io.*;
    import java.util.*;
    import java.util.StringTokenizer;
    public class blerk
         public static void main(String[] args) throws IOException
              InputStreamReader stdin = new InputStreamReader(System.in);
              BufferedReader br = new BufferedReader(stdin);
              boolean e = true;
              String str = "";
              String symbol = "";
              int value0 = 0;
              int value1 = 0;
              int value2 = 0;
              System.out.print(">");
              str = br.readLine();
              StringTokenizer st = new StringTokenizer(str, " ");
              int i = 0;
              int option = 0;
              while (st.hasMoreTokens())
                   switch(i)
                        case 0:
                             symbol = st.nextToken();
                             // This part is obviously not correct. How can this be implemented to select and store the operating procedure the user enters?
                             if(symbol = "e")
                                  System.exit(0);
                             }else
                             if(symbol = "c")
                             }else
                             if(symbol = "+")
                                  option =
                        break;
                        case 1:
                             value0 = Integer.parseInt(st.nextToken());
                        break;
                        case 2:
                             value1 = Integer.parseInt(st.nextToken());
                        break;
                        case 3:
                             value2 = Integer.parseInt(st.nextToken());
                        break;
                        default:
                             System.out.println("format: >operator x y z");
                        break;
                   i++;
              System.out.println(symbol + value0 + value1 + value2); //test
    Any advice would be most appreciated.
    Benjamin.

  • Update to 10.6.8 and HP F2100 and D2400 Printers stopped working. Restored 10.6.7 and printers from Install CD's but not working,  Same with scanner

    Help....
    Updated to 10.6.8 and HP F2100 and D2400 Printers stopped working.
    Restored 10.6.7 and printers from Install CD's but not working.
    Same with F2100 scanner
    Am I glad I kept Windows desktop as without it I would be scre**ed now
    What is going on with this latest update as its like a return to Windows with things crashing or hanging up every few minutes????
    On a MacBook Air that has not been updated everything still works so what has 10.6.8 done and why won't the restore to 10.6.7 work?
    Steve

    None of those things you mentioned were what I suggested.
    I'm guessing the "ctrl click in printer preferences" means you Reset the Printing System?
    If so, that is what I would have suggested if deleting it by selecting the ( - ) button and then adding it with the ( + ) button.
    But, if HP has a fix, it likely needs to update its drivers.

  • My macbook is back from repairs. It is not working with my apple led cinema display. It was working prior to the repairs on the laptop. Is there a setting I don't know about that might have been changed?

    My macbook pro is just back from repairs.  It is not working with my apple led cinema display. I have followed the directions in the cinema display manual.  am I missing something?

    Take a look at the Displays preference panel to see if everything is ok, particularly the resolution and refresh rate.  Displays will probably try to put the panel for the ACD on the ACD where you won't see it.  So click "Gather Windows" to get the ACD panel on to your macbook.
    One more thing, make sure you fully seated the mini displayport plug.  They can be sneaky little devils in that they need to be fully pushed in.

  • Procurement w/o material from vendor with plant assignment not defined

    While creating  standard Framework Order (FO)   asset  PO  I am getting the below error
    "procurement w/o material from vendor with plant assignment not defined"
    Plz Help
    Regards

    Dear INDRANIL BHATTA ,
         Thanks for your reply and your soluation ,
    Finally , I found Vendor Master assignment to plant so it can't create FO PO .
    ->  XK02 -> selecting "purchasing data" >Extras>Add.Purchasing data.

  • I bought an unlocked iphone 4s from dubai but it does not work with an indian idea sim..help

    i bought an unlocked iphone 4s from dubai but it does not work with an indian idea sim..help

    If you are both on the T-mobile network, the sim card should work.  If you did a Erase All Content and Settings, then she should be at the point of activation as a new device...talk to T-mobile and be sure the sim she is using is a valid sim card.

  • Migration from PC with MA did not end. Had to shut down MacBookPro. After restart no new user was created. Can't find the transferred data (35 GB). Would like to delete it.

    Migration from PC with MA did not end. Had to shut down MacBookPro. After restart no new user was created. Can't find the transferred data (35 GB). Would like to delete it.

    iTunes is required to initially activate the phone. Back when the iPhone 3G was sold, you would take it out of the box and see a "Connect to iTunes" screen. She HAD to connect to a computer in order to begin using the phone. Does she remember what computer this was?

  • PR: Procurement w/o material from vendor with plant assignment not defined

    Hi,
    Getting the error message:  06806 - Procurement w/o material from vendor with plant assignment not defined
    while creating the PR with account assingment (P- project) & without material no. instead entering the short text in the PR.
    this issue (Error message) is getting to only one user.
    question-1:  Is it possible to set the Error messages to the user specific. Because other users are able to create the PR with the above inputs, but the one user is not able to create instead getting the above E- Msg.
    question-2: Is it possible to set the messages to Plant specific instead quesiton -1 or both
    Or else, please let me know how to deactivate the above E-msg to the specific user.
    Please do the needful asap.
    Regards,
    Sapsrin

    Hi,
    As you noticed, note 856962 has changed the system behaviour
    when you are working with procurement w/o material from vendor with
    plant assignment.
    Items without a material master record can only be ordered from vendors
    without a plant assignment.
    This note will stop your users from creating service purchase orders
    for a vendor who has a Plant assigned in the vendor master, issuing
    the error message 06 806.
    you can check the below code:-
    LMEPOF23
      IF ekpo-ematn IS INITIAL AND
          (  aktyp EQ hin OR ekko-reswk NE oekko-reswk  OR      "856962
         (  aktyp EQ hin OR NOT ekko-reswk IS INITIAL OR        "856962
            ekko-bsakz NE oekko-bsakz OR
            gf_extended_check NE space ).
        PERFORM enaco_2(sapfmmex) USING '06' '806'.
    regards,
    Lalita

  • My speakers from my iPhone 4S is not working I'm clicking on the buttons on the side nd the volume is not even showing getting louder or lower but when I plug in my ear phones I can hear it juss happen out of no where what sould I do ?

    My speakers from my iPhone 4S is not working I'm clicking on the buttons on the side nd the volume is not even showing getting louder or lower but when I plug in my ear phones I can hear it juss happen out of no where what sould I do ?

    Your iPhone charging port may have a minor short, causing iPhone to falsely sense it is connected to a dock turning off its speaker. Clean iPhone charging port with a clean dry toothbrush.

  • HT5622 my apple id is not working when i sign in from my laptop it works but when i sign in from my iphone4 then its not working it gives the message of "your aapleid or password is incorrect"? how can i solve this problem please help

    my apple id is not working when i sign in from my laptop it works but when i sign in from my iphone4 then its not working it gives the message of "your aapleid or password is incorrect"? how can i solve this problem please help

    Hey nocillado,
    Thanks for using Apple Support Communities.
    It sounds like you have 2 things you want to address. These articles can help you use iCloud with your existing Apple ID.
    Get help activating your iPhone
    http://support.apple.com/kb/ts3424
    Using your Apple ID for Apple services
    http://support.apple.com/kb/ht4895
    Using the same Apple ID for Store purchases and iCloud (recommended)
    Have a nice day,
    Mario

  • BIP report security from Dashboard to Publisher is not working

    Hi ,
    I created a BIP report(.xdo) and placed it on Dashboard as a link . As admin , I can see the report . As a user , I am able to get into publisher but not able to see the report . Iam getting the below error message .
    Error : Unauthorized Access: please contact the administrator.
    I suspect that security model from Dashboard through BIP is not working . I tried searching the online resources but couldnt find right help .
    Iam a newbie for BIP , I followed the regular BIP guides , configured eveything as per the docs and things work as admin . But I want to test the security as user .
    Where Iam doing wrong , Any ideas please help .
    Thanks
    Karthik

    Hello Vijay ,
    I have grant permissions to the user and the report in BI webcatalog and also in BIP under admin tab I have addes the role which the user belongs to and also the shared folder . Still the problem exists.
    My BI presentation servcies security is working . My user security is also working , all that I need is the user should be able to see the report when he clicks on BIP link placed in dashboard.

  • Brand new Mac user help please! How do you connect a 17" monitor to the MacBook? I have the monitor plugged into the Mac, but the F8 that I am used to with PC does not work. Please help. Thanks.

    Brand new Mac user help please! How do you connect a 17" monitor to the MacBook? I have the monitor plugged into the Mac, but the F8 that I am used to with PC does not work. Please help. I am getting lots of spelling errors as the MacBook laptop screen is too small. Thank you so much! .

    Contentmom6 wrote:
    Brand new Mac user help please! How do you connect a 17" monitor to the MacBook? I have the monitor plugged into the Mac, but the F8 that I am used to with PC does not work.
    Normally, you just connect the monitor to the MacBook using a VGA adaptor that you can buy from an Apple Store.  Now try System Preferences > Displays > Detect Displays.  You should now be able to select a display mode for the monitor.  If it still doesn't work, then I'd check that everything is properly connected.  I've had problems with colours disappearing due to a faulty connection in the VGA adaptor.
    Bob

Maybe you are looking for

  • Placing a pdf on a page in Muse.

    Hello, Is there any way to place a pdf on a page in Muse so that it is plainly viewable on that page? I have tried converting it to an image such as a png but the quality goes down and it's not suitable. I know how to add a pdf with a link for downlo

  • CCD+ Limitations

    Is anyone sending ACH payments in CCD+ format? If so, how are you controlling the 80 character description limit? Thanks for any input, Jennifer

  • Messed up Adobe process

    My Adobe Flash Player, which I need, and just uninstalled keeps asking me to accept or deny to allow companies to store things on my computer. This will NEVER be allowed. Why is this happening? I trust Adobe but in NO WAY outside companies. Most of t

  • Designer 7.1 Not Responding error

    I have LifeCycle Designer 7.1 and have just received and XDP file that I need to modify. It's a one pager, but is somewhat large (600kb). It has a few images embedded (approximately 10 of varying sizes). It loads up fine, albeit slow. But whenever I

  • HT201406 i phone 4 various buttons do not respond & connot access contacts list

    i phone 4 various buttons do not respond & cannot access contact list l