Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

init param doubt

 
lusha tak
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Class Generic Servlet has alredy got getInitParameter() method defined in it.Then why do we have to retreuve param like:
this.getServletConfig.getInitParameter("some param name");

Why cant we directly use the following:
this.getInitParameter("some param name");

I was wondering may be context param need to be accessed using this method -but there again we use

this.getServletContext.getInitParamater("param Name");

Can anybody please throw some light?

Thanks in advance..

Lusha
 
DPuttJaTT
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been using the same code,
---
1. set init params in web.xml
2. read in servlet (deployed on Tomcat 5.5.9) with either
- this.getInitParameter(paramName)
- this.getServletConfig().getInitParameter(paramName)
---

I have not faced any problem. Or is it that I am able to understand your query.
 
lusha tak
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes thats what my query is...Thanks!!
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The this.getInitParameter(String) and this.getServletConfig().getInitParameter(String) methods used to get the servlet paraleters which are specific to servlet. There are defined in web.xml under <servlet> element.
<servlet>
<servlet-name> xx </servlet-name>
<servlet-class> Some Class </servlet-class>
<init-param>
<param-name>param1</param-name>
<param-value>value1</param-value>
</init-param>
</servlet>

As the GenericServlet implements the ServletConfig interface, we can extract these values in the above two ways. ( Why GenericServlet implements the ServletConfig interface that I don't know)

The this.getServletContext().getInitParameter(String) method is used to get the parameters which are web application specific. These parameters are defined under <context-param> element of web.xml directly under <web-app ... >.

I hope this is answer to your query.

thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic