• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 597
  • Last Modified:

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

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  

  • 3
1 Solution
did you try

String p = getServletContext().getInitParameter("MySQLConnection");
Make sure web.xml is in the right place

Thanks for the Grade :)
Good Luck

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now