• 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:
 <context-param>
  <param-name>MySQLConnection</param-name>
  <param-value>jdbc:mysql://localhost/paygo_com","root","bimini01"</param-value>
</context-param>

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

<servlet>
    <servlet-name>DataRequestor</servlet-name>
    <servlet-class>model.DataAccess.DataRequestor</servlet-class>
 </servlet>
<servlet-mapping>
    <servlet-name>DataRequestor</servlet-name>
    <url-pattern>*.DataRequestor</url-pattern>
  </servlet-mapping>

??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  




0
paygo
Asked:
paygo
  • 3
1 Solution
 
koppchaCommented:
did you try

String p = getServletContext().getInitParameter("MySQLConnection");
0
 
koppchaCommented:
Make sure web.xml is in the right place
/Application_Root_Directory/WEB-INF/web.xml

0
 
koppchaCommented:
Thanks for the Grade :)
Good Luck
0

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