Results 1 to 6 of 6
- 01-19-2009, 07:42 AM #1
Member
- Join Date
- Jan 2009
- Posts
- 9
- Rep Power
- 0
How to read from and write to .properties file from a jsp
Hi all,
I'm a novice to java.
Initially we used to make changes in the properties file manually and restart the tomcat services for changes to take place.
Now, we need to read from and write to values from .properties file through GUI and avoid restart.
I have created a new jsp that displays the fields that are some of the key values of the properties file.(eg. SMTP_Servers_And_Ports).
I have an editable text box after every label in the screen.
My requirement is :
1) The default values( from .properties) for these fields should populate automatically when I open the screen.
2) They should be editable which means if I change the values, they should reflect in the .properties file.
3) These changes should be seen in the properties file without restarting tomcat.
Can someone please help me ?
I would be grateful to you.
Thanks a lot in advance !!
Regards,
Magnum
- 01-19-2009, 07:56 AM #2
For exapmle your property file database.properties contains:
Java Code:jdbc.drivers=org.postgresql.Driver jdbc.url=jdbc:postgresql:COREJAVA jdbc.username=dbuser jdbc.password=secret
Your bean file should have a method wich will contain following:
Thus you load proeprties from the properties file and make a connection to the db server.Java Code:Properties props=new Properties(); FileInputStream in=new FileInputStream("database.properties"); props.load(in); in.close(); String drivers=props.getProperty("jdbc.drivers"); id(drivers!=null) System.setProperty("jdbc.drivers", drivers); String url=props.getProperty("jdbc.url"); String username=props.getProperty("jdbc.username"); String password=props.getProperty("jdbc.password"); return DriverManager.getConnection(url,username,password);
- 01-19-2009, 09:07 AM #3
Member
- Join Date
- Jan 2009
- Posts
- 9
- Rep Power
- 0
Hi Serjant,
Sorry if I'm being silly.
But I do not have a bean file.
I have a servlet class instead.
So how should I proceed ??
Please help !
- 01-19-2009, 09:11 AM #4
Member
- Join Date
- Jan 2009
- Posts
- 9
- Rep Power
- 0
Also, we use the Oracle database.
The DBParameters.properties looks something like this :
DataBaseName=XYZ
DBInUse=Oracle
DataBaseDriver=oracle.jdbc.driver.OracleDriver
Poolsize=99
Password=admin
DataAccessClass=dataaccess.oracle.api.OracleDBProx y
BaseURL=jdbc\:oracle\:thin\:@localhost\:1521\:
UserId=abc
- 01-19-2009, 09:13 AM #5
Then you insert the lines of code i have previously posted into the get or post method,but without return statement,then with the help of DriverManager you set the connection,and make a redirect to the preferred jsp page
- 01-20-2009, 09:08 AM #6
Member
- Join Date
- Jan 2009
- Posts
- 9
- Rep Power
- 0
Similar Threads
-
Read and Write file
By mrdestroy in forum New To JavaReplies: 13Last Post: 10-31-2008, 12:11 PM -
DES algorithm (Read and Write bytes to file)
By JoaoPe in forum Advanced JavaReplies: 6Last Post: 07-29-2008, 03:46 PM -
File read/write problems
By p900128 in forum New To JavaReplies: 4Last Post: 06-27-2008, 12:15 AM -
Read/Find Substring/Write to new file
By hiklior in forum New To JavaReplies: 6Last Post: 04-23-2008, 02:47 AM -
Read-File Write Display substring
By hiklior in forum New To JavaReplies: 3Last Post: 04-18-2008, 11:45 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks