File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Android Security Essentials Live Lessons this week in the Android 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.
I agree. Here's the link:
subject: init() and ServletContext attribute
Similar Threads
send variable value from one servlet to another servlet for itext pdf
Login Servlet
init and destroy method
Can not get context attribute
Class cast Exception