passing parameters through web.xml always returns null....
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Luciana_Soligo
Posted On:   Tuesday, September 18, 2001 07:28 AM

I've added the following entry to web.xml but I always get Null from getInitParameters("porperties")

-
IspiServlet
com.entegrity.atdemo.servlet.IspiServlet
-
properties
vnbvnvnb

Re: passing parameters through web.xml always returns null....

Posted By:   Alex_Chaffee  
Posted On:   Tuesday, September 18, 2001 07:05 PM

Re: passing parameters through web.xml always returns null....

Posted By:   AlessandroA_Garbagnati  
Posted On:   Tuesday, September 18, 2001 10:20 AM

Luciana,

You can have two types of 'init parameters'.



The first one is the one of the Servlet Context. To use them you need to put in the web application descriptor (web.xml) something like this:




context_param_1
1


context_param_2
2

...


These parameters can be retrieved by any servlet (or JSP) using the ServletContext object. In a servlet you can do:

// inside the init() method:
ServletContext context = config.getServletContext();
String context_param_1 = context.getInitParameter("context_param_1");
String context_param_2 = context.getInitParameter("context_param_2");

// inside the service() or doXXX() methods:
ServletContext context = this.getServletContext();
String context_param_1 = context.getInitParameter("context_param_1");
String context_param_2 = context.getInitParameter("context_param_2");



The second type of parameter is a servlet or jsp specific init parameter that can be only used only in the specific servlet. This is the one you are trying to use according to the definition of the web application descritor (web.xml) that you have provided:

...

IspiServlet
com.entegrity.atdemo.servlet.IspiServlet

properties
vnbvnvnb


...

In this case the servlet or the jsp will be able to read the parameter using:

String param = getInitParameter("properties");



Now, there are two errors in the statement that you have reported in your message:

"porperties" (it should be "properties")

getInitParameters (it should be getInitParameter).


I don't know if they are both typos, but if not that the reason why your code doesn't work. I normally use the init parameters in both servlets, jsps, and context and I've never had any problem in reading them.


What you can do, is to test the parameters reading all the names with getInitParameterNames() that will return you an enumeration, and then print all them out, to see what do you have.

About | Sitemap | Contact