Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using getInitParameter in Java application with JSP pages

Posted on 2007-11-22
5
Medium Priority
?
1,943 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 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

Amazon Web Services EC2 Cheat Sheet

AWS EC2 is a core part of AWS’s cloud platform, allowing users to spin up virtual machines for a variety of tasks; however, EC2’s offerings can be overwhelming. Learn the basics with our new AWS cheat sheet – this time on EC2!

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
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:
Suggested Courses

715 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