Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Doubt on servlets

 
Padma priya Gururajan
Ranch Hand
Posts: 437
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Given the partial Deployment Descriptor:
<context-param>
<param-value>email</param-value>
<param-value>foo@bar.com</param-value>
</context-param>


<servlet>
<servlet-name>a</servlet-name>
<servlet-class>com.bar.Foo</servlet-class>
<init-param>
<param-name>email<param-name>
<param-value>baz@bar.com</param-value>
</init-param>
</servlet>

And assuming scfg is a servletconfig object and sctx is a servletcontext object, how does
scfg.getServletContext().getInitParameter("email") return foo@bar.com?

My doubt is how scfg is assosicated with servletcontext?

Please help me.
With regards,
Padma priya N.G.
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this a doubt or a question?

If it is a question, please take a look at the API and see what the association between the objects is. that should help you.
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry I could not answer more fully in my earlier post.

HttpServlet has 2 methods (inherited from GenericServlet) called getServletConfig and getServletContext. getServletConfig returns a ServletConfig object that has a getServletContext method. Both getServletContext methods return the same object. This is just the way GenericServlet and HttpServlet were designed. Try executing the 2 calls to obtain the ServletContext from your HttpServlet class and you will see that they return the same ServletContext object
 
Padma priya Gururajan
Ranch Hand
Posts: 437
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Michael,
Thanks for the nice explanation.
With regards,
Padma priya N.G.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!