Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Using getInitParameter in Java application with JSP pages

Posted on 2007-11-22
5
Medium Priority
?
1,952 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
5 Comments
 
LVL 92

Assisted Solution

by:objects
objects earned 1200 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 300 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 1200 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

Independent Software Vendors: 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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

972 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