Read values  from WEB.XML file or STRUTS-XML.config FILE

Posted on 2005-04-24
Last Modified: 2008-02-01
Hello All,

I have a .NET background so I need some advice on reading a value from either the
WEB.XML File or the STRUTS-XML.config file. I am developing with STRUTS

Problem: I want to keep a MySQL database connection string in some XML file.
I know I can use either the WEB.XML or the STRUTS-XML.config file.

Question 1: Is it true that if I use the WEB.XML file approach:
such as:

?? Is it true that only a servlet - defined to in the WEB.XML file such as:


??can read the WEB.XML values?

I tried this approach and get a null pointer exception. using getServletContext().

Question 1A)

I know that  STRUTS really doesn't like this approach, but I don't want to read the
XML value from the Controller / Action Servlet.  Don't like this approach.

I'd rather my 'DataAccess.DataRequestor' class call some XML file directly (could be anywhere) to get the DataBaseConnection string - (at start up).  

.....please advise - I'd like to try both approaches once just for the knowledge  

Question by:paygo
    LVL 8

    Expert Comment

    did you try

    String p = getServletContext().getInitParameter("MySQLConnection");
    LVL 8

    Accepted Solution

    Make sure web.xml is in the right place

    LVL 8

    Expert Comment

    Thanks for the Grade :)
    Good Luck

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Suggested Solutions

    Title # Comments Views Activity
    maven scope 1 117
    lessBy10  challenge 15 84
    excpetion with multiple catch 11 97
    spring JDBC Template example error 26 114
    Great sound, comfort and fit, excellent build quality, versatility, compatibility. These are just some of the many reasons for choosing a headset from Sennheiser.
    For Sennheiser, comfort, quality and security are high priority areas. This paper addresses the security of Bluetooth technology and the supplementary security that Sennheiser’s Contact Center and Office (CC&O) headsets provide.  
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now