This week's giveaways are in the MongoDB and Jobs Discussion forums. We're giving away four copies of Mongo DB Applied Patterns and 4 resume reviews from Five Year Itch and have the authors/reps on-line! See this thread and this one for details.
Hi, I am running Tomcat 3.1 and as per the documentation I have put the initialization parameters in web.xml in webapps\root\web-inf folder. I still cann't get these parameters using the getInitParameter() method of ServletConfig. I have made sure that the name and case of the parameter I am using is correct. I am using following code in a servlet to access the parameter: public void init(ServletConfig config ) throws ServletException{ super.init(config); parameter1 = config.getInitParameter("param1"); ........ I always get the value of "parameter1" variable as null. Any help is highly appreciated. Thanks! Shekhar.
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12265
1
posted
0
My first guess is that something about your web.xml file does not agree with the way your servlet is being invoked. If you are not starting the servlet using the name in web.xml then you won't be able to see the init parameters. What does your web.xml entry for this servlet look like? Bill
Hi William, Thanks! I was using the wrong name of the servlet in web.xml. It really helps to talk to somebody when you know there is something obviously wrong but you cann't see it. Thanks again. Shekhar.
Phil Hanna
Ranch Hand
Joined: Apr 05, 2001
Posts: 118
posted
0
By the way, the web.xml deployment descriptor also allows you to provide initialization parameters that are not tied to any particular servlet: <web-app> ... <context-param> <param-name>JDBC.DRIVER</param-name> <param-value> org.enhydra.instantdb.jdbc.idbDriver </param-value> </context-param> ... <servlet> <servlet-name>servlet1</servlet-name> <servlet-class>servlet1</servlet-class> </servlet> <servlet> <servlet-name>servlet2</servlet-name> <servlet-class>servlet2</servlet-class> </servlet> ... </web-app> In the example above, you could retrieve the JDBC driver class name in either servlet1 or servlet2 as follows: ServletContext context = getServletContext(); String className = context.getInitParameter("JDBC.DRIVER"); or in a JSP: <% String className = application.getInitParameter("JDBC.DRIVER"); %>
Phil Hanna<BR>Sun Certified Programmer for the Java 2 Platform<BR>Author of :<BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072127686/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">JSP: The Complete Reference</A><BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072124253/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">Instant Java Servlets</A>