This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
I have a servlet which has a help action class that handles its request and response objects and set some attribute with it. This servlet then forwards to a jsp page finally. In this servlets's action class, it handles some business logics like database access. So I have another database access class, in this class "DB.java"where DBFinder is a class that reads the Database information file and returns the Database name, port number, etc. The interesting and intriguing thing is: if I comment line --(1) and use line 2, 3. it keeps giving me "java.lang.IllegalArgumentException". if I comment line 2, 3 and use line 1, everything works fine. Now the interesting thing is -- If I use a separate tester class to test , I found dbFinder.get_DB_NAME() does return "MyDatabase".
It seems it just can't be put here. I don't know what's the problem. can somebody help ???
Thanks, Mike - added code tags (MDC) [ February 27, 2002: Message edited by: Mike Curwen ]
Is there a reason you're not using a Properties object for this? It was made specifically for exactly what you're trying to do in DBFinder.
As for your IllegalArgumentException, can you provide the stack trace? There is nothing obvious that might be causing it. [ February 27, 2002: Message edited by: Mike Curwen ]
Joined: Apr 11, 2001
u just need to use the properties to read that.
hope it will solve
Joined: Feb 26, 2002
Mike and Prabhat, Thank you so much for the help. It turned out that I made a silly mistake that I messed up with the file path, I gave a relative path and somehow it couldn't find it. After fixing that, it all worked well. Your help is highly appreciated. Now, I have one more question here: I just want to make sure that "myproperty.txt" file does NOT contain any variable name that is(are) identical to the system's existing ones, otherwise it will mess everything up. So I checked the SUN web, it says the following is the complete list of runtime system properties: file.separator" File separator (for example, "/")
"java.class.path" Java classpath "java.class.version" Java class version number "java.home" Java installation directory "java.vendor" Java vendor-specific string "java.vendor.url" Java vendor URL "java.version" Java version number "line.separator" Line separator "os.arch" Operating system architecture "os.name" Operating system name "os.version" Operating system version "path.separator" Path separator (for example, ":") "user.dir" User's current working directory "user.home" User home directory "user.name" User Now, can I assume that as long as I DON'T give any property name same as any of above, it will be safe ??? So, I can feel free to write something like ... PORT=7100 PORT_NUMBER=7100 SERVER=sunmachine ... and don't need to worry about messing up any real system properties ? Thanks, Mike
The problem is... every user's system will be different. If you are running on Windows or on Solaris or on Linux, the system property values will be different, and perhaps there are more or less properties themselves. And that doesn't look anything close to a full list. Run this code to see what your own system properties are:
Beyond that issue, why would it mess up anything, unless you put them into the System property space by doing code like: Just don't do that, and you're fine.
And as a last question. You are using this in the context of a servlet. Is there any reason you are not using the facility provided to you by the servlet container? ( env-entry, context-param, init-param )