This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes init() and ServletContext attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "init() and ServletContext attribute" Watch "init() and ServletContext attribute" New topic

init() and ServletContext attribute

priya rishi
Ranch Hand

Joined: Oct 26, 2008
Posts: 119
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
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
From the servlet specification (see Servlet FAQ for links), see the bold part:

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
priya rishi
Ranch Hand

Joined: Oct 26, 2008
Posts: 119
my program worked!!!

finally it prints, Hello Java!!!
thanks for the servlet spec helped.
Don't get me started about those stupid light bulbs.
subject: init() and ServletContext attribute
Similar Threads
init and destroy method
Can not get context attribute
Class cast Exception
Login Servlet
send variable value from one servlet to another servlet for itext pdf