Solved

Using getInitParameter in Java application with JSP pages

Posted on 2007-11-22
5
1,927 Views
Last Modified: 2013-11-24
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?
0
Comment
Question by:kineticexpert
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 92

Assisted Solution

by:objects
objects earned 400 total points
ID: 20333606
your have to pass the value (or somewhere they can access them from)
0
 
LVL 4

Assisted Solution

by:jcoombes
jcoombes earned 100 total points
ID: 20333722
PAss through a reference to your ServletContext to the Java classes that need to access this information.

Cheers


JC
0
 
LVL 11

Expert Comment

by:Manish
ID: 20334300
Which patter ur following? From where you are accessing these classes?
0
 

Author Comment

by:kineticexpert
ID: 20336450
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
 
LVL 92

Accepted Solution

by:
objects earned 400 total points
ID: 20336545
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question