Solved

Using getInitParameter in Java application with JSP pages

Posted on 2007-11-22
5
1,892 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 400 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Which patter ur following? From where you are accessing these classes?
0
 

Author Comment

by:kineticexpert
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
for loop with Set 4 45
triangle challenge 4 75
json format text only 4 64
best (free) software to access postgres db (java) 1 17
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now