Solved

Using getInitParameter in Java application with JSP pages

Posted on 2007-11-22
5
1,911 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
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

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
null output 3 42
Selenium docs api java index 3 67
Bot application - advice 3 62
Delete .class files at every compile 4 20
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…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

733 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