Re: How to read data from web.xml (JSP)?



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.)

.



Relevant Pages

  • Re: How to read data from web.xml (JSP)?
    ... What to do if i dont want to hard-code the database driver and server ... the context object is not null and its value is: ...
    (comp.lang.java.programmer)
  • How to read data from web.xml (JSP)?
    ... What to do if i dont want to hard-code the database driver and server ... the context object is not null and its value is: ...
    (comp.lang.java.programmer)
  • Re: Is there a BEA Tuxedo equivalence in Java?
    ... > ContextCallback is not passed from the client to server. ... > .setContextCallback to register) with the context object. ... a Request object is passed as an argument. ...
    (comp.object)
  • Re: Hied Query String
    ... You can hide querystrings only when using frames ... But there is another way to do exactly what you want that doesn`t use session, cache or cookies, and it is the Context object ... the context is server side and only alive for the current server transfer. ... personally i combine this technique with hidden fields to store my information, when an event takes place that should bring me to anaother page and i need the values i simply get them out of the hiddenfield store them in a context object perform a transfer and get them out of the context, as soon as the current request is out of scope the context object is emptied this in contradiction to the session wich will hold a copy of the values as long as the session is alive. ...
    (microsoft.public.dotnet.languages.vb)
  • Server.Transfer
    ... Can I user Server.Transfer between two different web sites on the same ... And pass data via the Context object? ... Andrew Robinson ...
    (microsoft.public.dotnet.framework.aspnet)