Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

init() and ServletContext attribute

 
priya rishi
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am trying to set an attribute for the ServletContext in init(ServletConfig) and get the attribute in the doGet() of the servlet.
but i get null.i dont know what i am doing wrong.any help.

 
Carol Enderlin
drifter
Ranch Hand
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the servlet specification (see Servlet FAQ for links), see the bold part:

init(ServletConfig)
public void init(ServletConfig config)
throws ServletException
Called by the servlet container to indicate to a servlet that the servlet is being
placed into service. See Servlet.init(ServletConfig) .
This implementation stores the ServletConfig object it receives from the
servlet container for later use.
When overriding this form of the method, call
super.init(config)
.
 
priya rishi
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my program worked!!!

finally it prints, Hello Java!!!
thanks for the servlet spec quote.it helped.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic