S
Sameer
Dear All,
I am using Tomcat 6.0 on Windows XP SP2.
What to do if i dont want to hard-code the database driver and server
address etc. into code.
I put it into web.xml as follows:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID">
<display-name>ithelplinereports</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>db_driver</param-name>
<param-value>oracle.jdbc.driver.OracleDriver</param-value>
<param-name>db_server</param-name>
<param-value>192.168.31.41</param-value>
<param-name>db_port</param-name>
<param-value>1521</param-value>
</context-param>
</web-app>
I used the following code to access it in JSP.
ServletContext context = getServletContext();
String driver = context.getInitParameter("db_driver");
String server = context.getInitParameter("db_server");
String port = context.getInitParameter("db_port");
<%
System.out.println(driver);
%>
But I am getting the null values on the console.
By using System.out.println(context), I noted that
the context object is not null and its value is:
org.apache.catalina.core.ApplicationContextFacade@1a0d866
Then why I am getting the null value for
context.getInitParameter("db_driver").
Please revert.
Is this the right way to read data from web.xml? Any suggestions?
-Sameer
I am using Tomcat 6.0 on Windows XP SP2.
What to do if i dont want to hard-code the database driver and server
address etc. into code.
I put it into web.xml as follows:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID">
<display-name>ithelplinereports</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>db_driver</param-name>
<param-value>oracle.jdbc.driver.OracleDriver</param-value>
<param-name>db_server</param-name>
<param-value>192.168.31.41</param-value>
<param-name>db_port</param-name>
<param-value>1521</param-value>
</context-param>
</web-app>
I used the following code to access it in JSP.
ServletContext context = getServletContext();
String driver = context.getInitParameter("db_driver");
String server = context.getInitParameter("db_server");
String port = context.getInitParameter("db_port");
<%
System.out.println(driver);
%>
But I am getting the null values on the console.
By using System.out.println(context), I noted that
the context object is not null and its value is:
org.apache.catalina.core.ApplicationContextFacade@1a0d866
Then why I am getting the null value for
context.getInitParameter("db_driver").
Please revert.
Is this the right way to read data from web.xml? Any suggestions?
-Sameer