File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How does config.getInitParameter( ) know where to get the parameter.

 
lin xy
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a web application.
File -web.xml:
<servlet>
....
<init-param>
<param-name>name</param-name>
<param-value>value</param-value>
</init-param>
</servlet>
some servlet file:
...
public void init(){
ServletConfig config=getServletConfig();
param=config.getInitParameter("name");//get value here
}
...

q1:how does config.getInitParameter()know which file to read?
q2:how does config.getInitParameter() know which tag to read in file web.xml?
 
Ajith Kallambella
Sheriff
Posts: 5782
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Servlets forum...
 
R K Singh
Ranch Hand
Posts: 5382
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by lin xy:
There is a web application.
File -web.xml:
<servlet>
....
<init-param>
<param-name>name</param-name>
<param-value>value</param-value>
</init-param>
</servlet>
some servlet file:
...
public void init(){
ServletConfig config=getServletConfig();
param=config.getInitParameter("name");//get value here
}
...

q1:how does config.getInitParameter()know which file to read?
q2:how does config.getInitParameter() know which tag to read in file web.xml?

Ans for both questions:
It reads the web.xml which is under ContextName/WEB-INF directory.
Path upto ContextName is defined, in case of Tomcat, in server.xml.
HTH
 
arul murug
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
q1:how does config.getInitParameter()know which file to read?
q2:how does config.getInitParameter() know which tag to read in file web.xml?

To answer your questions Web container reads the web.xml file for the application and creates the servletconfig object when it loads your web application.From servletconfig you get these parameters using getInitParameter().
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic