S
Sameer
Dear All,
My web.xml is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID">
<display-name>Reports</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.htm</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>
</context-param>
<context-param>
<param-name>db_server</param-name>
<param-value>192.168.31.41</param-value>
</context-param>
</web-app>
I able to acess it in the JSP using
ServletContext context = getServletContext();
String driver = context.getInitParameter("db_driver");
String server = context.getInitParameter("db_server");
I have also written a Java class in the Web App as:
import java.sql.*;
public class DBUtils {
public DBUtils() {
}
public static Connection getDBConnection(String driver, String
conn_url,
String db_username, String db_password) throws Exception {
Class.forName(driver).newInstance();
Connection con = DriverManager.getConnection(conn_url, db_username,
db_password);
return con;
}
}
I can get DB connection for the JSP using this:
con = DBUtils.getDBConnection(driver, conn_url, username,
db_password);
But then i have to depend on the external parameters from JSP.
Can i access the context parameters in the java class?
As i checked ServletContext is not getting resolved in the java class
Any way to access the data from web.xml in java class?
Please revert.
-Sameer
My web.xml is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID">
<display-name>Reports</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.htm</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>
</context-param>
<context-param>
<param-name>db_server</param-name>
<param-value>192.168.31.41</param-value>
</context-param>
</web-app>
I able to acess it in the JSP using
ServletContext context = getServletContext();
String driver = context.getInitParameter("db_driver");
String server = context.getInitParameter("db_server");
I have also written a Java class in the Web App as:
import java.sql.*;
public class DBUtils {
public DBUtils() {
}
public static Connection getDBConnection(String driver, String
conn_url,
String db_username, String db_password) throws Exception {
Class.forName(driver).newInstance();
Connection con = DriverManager.getConnection(conn_url, db_username,
db_password);
return con;
}
}
I can get DB connection for the JSP using this:
con = DBUtils.getDBConnection(driver, conn_url, username,
db_password);
But then i have to depend on the external parameters from JSP.
Can i access the context parameters in the java class?
As i checked ServletContext is not getting resolved in the java class
Any way to access the data from web.xml in java class?
Please revert.
-Sameer