Using getInitParameter in Java application with JSP pages

I have a web application, which has previously used solely JSP pages and accessed properties in the web.xml file using:
getServletContext().getInitParameter("property_name");

I have since added some Java classes to this application to do various bits and pieces of work, and I am not sure how to access the same information from the web.xml file?

Can someone please advise (or provide a code snippet) as to how to access this information from a java class?
kineticexpertAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
objectsConnect With a Mentor Commented:
you could do that, or just pass the parameter(s) it needs

   ServletContext sContext = ServletContext.getServletContext();
   Emailer email1 = new Emailer(sContext.getInitParameter("property1"), sContext.getInitParameter("property2"));
0
 
objectsConnect With a Mentor Commented:
your have to pass the value (or somewhere they can access them from)
0
 
jcoombesConnect With a Mentor Commented:
PAss through a reference to your ServletContext to the Java classes that need to access this information.

Cheers


JC
0
 
ManishLeadCommented:
Which patter ur following? From where you are accessing these classes?
0
 
kineticexpertAuthor Commented:
I am using Netbeans to develop this project, are you saying that I should pass through like so,..?

                                 
                                ServletContext sContext = ServletContext.getServletContext();
                                  Emailer email1 = new Emailer(sContext);

and then it should work (I'm not at work so I cannot test it yet)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.