*
The moose likes Servlets and the fly likes how to access init/property parameters inside bean classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to access init/property parameters inside bean classes" Watch "how to access init/property parameters inside bean classes" New topic
Author

how to access init/property parameters inside bean classes

Shashank Rudra
Ranch Hand

Joined: Mar 26, 2009
Posts: 131
Hi guys

Here I have a bean class which updates the database. This may be seen as a DAO class. In this bean's method we are calling a COBOL program based on some criteria. This bean's method is being called though many other calls. These calls are to methods declared in other beans. These calls are originally being initiated out of a servlet (the general course in web application scenario).

Now we want a configurable option, may be a check box at the start of the application loading. This will affect which COBOL program will be called in THEBEAN method.

One way is to edit all the method call starting with the first one in the chain of method calls. But I think that will be a lazy way to do that. Also will lead to bad code. So any one has an idea how to set this up in some properties file and read it from there. In the bean class we don't have access to context or config to get at the file stored on the server. Please help me see it through. TIA.

I am using Tomcat 5.0 Sevlet 2.4 JDK1.5 on windows XP.


Programmer Analyst || J2EE web development/design
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

Store a properties file in the classpath. It can be accessed from anywhere.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Shashank Rudra
Ranch Hand

Joined: Mar 26, 2009
Posts: 131
Thanks Bear for quick response. Here is what I am trying to do
(but am not able to get the results as desired please tell what I need to do different)

Code I am using in a servlet, where I have access to session/servletContext. The file is inside the WEB-INF directory as in the path above. Now to
access the same properties file inside a bean class where I don't have
access to session and context objects. As said in the first post- I don't
want to keep them passing through chain of method calls which are 6-8 in number.

I am trying
And this is the error that I am getting Other paths that I have tried with are -
/properties/myProject.properties
./properties/myProject.properties
properties/EZRithm.properties

I am using Tomcat5.0 Servlet2.4 JDK1.5 Eclipse Europa on Windows XP.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

The file is already on the classpath -- you should be using the normal Java properties mechanisms to load it -- not going through the servlet context. You're just making it hard on yourself.

Hint: ResourceBundle
Shashank Rudra
Ranch Hand

Joined: Mar 26, 2009
Posts: 131
Great Bear. Now I see it, thanks for the hint. I myself once thought to use that but was not sure.

Here is how I accessed itThe fileName that I used is properties.myProject.

Thanks a lot again Bear.
ravil baizhiyenov
Greenhorn

Joined: Oct 22, 2009
Posts: 16
I was looking for information about how to solve the same problem and came across this topic... Just to help others out with a similar issue, I'd encourage them to see the following article: http://www.javaworld.com/javaworld/javaqa/2003-08/01-qa-0808-property.html?page=1. I found it quite helpful...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to access init/property parameters inside bean classes
 
Similar Threads
Passed Part One with 87%
long post IBM.158
Can these methods exist...
who owns create() ?
ejbCreate in session bean