Re: How to read data from web.xml (JSP)?
- From: Sameer <dolpheen@xxxxxxxxx>
- Date: Sat, 29 Sep 2007 05:45:49 -0000
On Sep 28, 8:41 pm, "david.karr" <davidmichaelk...@xxxxxxxxx> wrote:
Below.
On Sep 28, 5:49 am, Sameer <dolph...@xxxxxxxxx> wrote:
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>
You're not using "context-param" correctly. Each "context-param"
element only takes a single "param-name" and "param-value" element.
I'm surprised this got past validation. I wouldn't be surprised if
the value of "db_server" is also null, but the value of "db_port" is
not.
Change this to three "context-param" elements, each with a "param-
name" and "param-value" element, and that should get you closer.
</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
Thanks!
(I am using Eclipse Europa and it not showing red mark anywhere.)
.
- Follow-Ups:
- Re: How to read data from web.xml (JSP)?
- From: Manish Pandit
- Re: How to read data from web.xml (JSP)?
- References:
- How to read data from web.xml (JSP)?
- From: Sameer
- Re: How to read data from web.xml (JSP)?
- From: david.karr
- How to read data from web.xml (JSP)?
- Prev by Date: Re: enabling directory listing on sun web server
- Next by Date: Re: notifying particular thread to wake up.
- Previous by thread: Re: How to read data from web.xml (JSP)?
- Next by thread: Re: How to read data from web.xml (JSP)?
- Index(es):
Relevant Pages
|