Click here to Skip to main content
15,900,468 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the data in the web.xml as
XML
<context-param>
      <param-name>vDriver</param-name>
      <param-value>com.mysql.jdbc.Driver</param-value>
     <!-- <description> ClassLoader of Driver </description>-->
 </context-param>

 <context-param>
      <param-name>vConnection</param-name>
      <param-value>jdbc:mysql://localhost:3306/cdr555</param-value>
<!--      <description> Connection to Database </description>-->
 </context-param>

 <context-param>
      <param-name>vConnectionA</param-name>
      <param-value>jdbc:mysql://localhost:3306/maindata</param-value>
<!--      <description> Connection to Database </description>-->
 </context-param>

 <context-param>
      <param-name>vConnectionB</param-name>
      <param-value>jdbc:mysql://localhost:3306/states_ap</param-value>
<!--      <description> Connection to Database </description>-->
 </context-param>

 <context-param>
      <param-name>vConnectionP</param-name>
      <param-value>jdbc:mysql://localhost:3306/personal</param-value>
<!--      <description> Connection to Database </description>-->
 </context-param>


 <context-param>
      <param-name>vUsername</param-name>
      <param-value>root</param-value>
<!--      <description> Username of Database </description>-->
 </context-param>

 <context-param>
      <param-name>vPassword</param-name>
      <param-value>sigma</param-value>
<!--      <description> Password of Database </description>-->
 </context-param>

Now, I want to access these values in the java class file by using the code:

Java
ServletContext sc =getServletConfig().getServletContext();
String vDriver = sc.getInitParameter("vDriver");
String vConnection = sc.getInitParameter("vConnection");
String vConnectionA = sc.getInitParameter("vConnectionA");
String vConnectionB = sc.getInitParameter("vConnectionB");
String vConnectionP = sc.getInitParameter("vConnectionP");
String vUsername = sc.getInitParameter("vUsername");
String vPassword = sc.getInitParameter("vPassword");

Using above code, I am retriving the values. But the values are not coming instead of that it is giving null values.

Please give the reply. its very urgent
Posted
Updated 23-Sep-10 5:40am
v2

1 solution

The parameters you're trying to read are context parameters, but you're reading them using getInitParameter, store them as init-parameters instead:

XML
<init-param>
    <param-name>local-server-port</param-name>
    <param-value>4242</param-value>
</init-param


Hope this helps,
Fredrik
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900