Results 1 to 6 of 6
  1. #1
    MAGNUM is offline Member
    Join Date
    Jan 2009
    Posts
    9
    Rep Power
    0

    Default 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

  2. #2
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    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:

    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);
    Thus you load proeprties from the properties file and make a connection to the db server.

  3. #3
    MAGNUM is offline Member
    Join Date
    Jan 2009
    Posts
    9
    Rep Power
    0

    Default

    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 !

  4. #4
    MAGNUM is offline Member
    Join Date
    Jan 2009
    Posts
    9
    Rep Power
    0

    Default

    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

  5. #5
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    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

  6. #6
    MAGNUM is offline Member
    Join Date
    Jan 2009
    Posts
    9
    Rep Power
    0

    Default

    Serjant,

    We do not have these entries in the database.
    We have to get these entries from a static file.
    So could you please tell me how to access this file ( hard-code the file path) and read and write values.

    Thanks a ton !!

Similar Threads

  1. Read and Write file
    By mrdestroy in forum New To Java
    Replies: 13
    Last Post: 10-31-2008, 12:11 PM
  2. DES algorithm (Read and Write bytes to file)
    By JoaoPe in forum Advanced Java
    Replies: 6
    Last Post: 07-29-2008, 03:46 PM
  3. File read/write problems
    By p900128 in forum New To Java
    Replies: 4
    Last Post: 06-27-2008, 12:15 AM
  4. Read/Find Substring/Write to new file
    By hiklior in forum New To Java
    Replies: 6
    Last Post: 04-23-2008, 02:47 AM
  5. Read-File Write Display substring
    By hiklior in forum New To Java
    Replies: 3
    Last Post: 04-18-2008, 11:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •