This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Read Property file on Server Side in GWT

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I want to read property file on Server side. I have DBConfig.java, useDBConfig.java and DBConfig.properties all placed in server package. I can't read the values from property file on Server Side. Your help is highly appreciated. Thanks in advance.


public interface DBConfig extends Constants {

@DefaultStringValue("host")
String host(String host);

@DefaultStringValue("port")
String port(String port);

@DefaultStringValue("username")
String username(String username);

@DefaultStringValue("password")
String password(String password);
}


public void useDBConfig() {

DBConfig constants = GWT.create(DBConfig.class);
Window.alert(constants.host());


host = constants.host(host);
port = constants.port(port);
username = constants.username(username);
password = constants.password(password);

}

property file...

host=127.0.0.1
port=3306
username=root
password=root
 
Bartender
Posts: 2326
100
Google Web Toolkit Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
snajeeb, GWT is intended to make javascript coding easier. The way it does this is by translating java to javascript.
Two inputs as per your question :
  • The Javascript code can statically only refer to client side code and not server side. Hence you should be including this in the client package
  • However, having said that, why do you even need to access database related configurations at your browser end ? Shouldn't the server side code be doing the same ?

  •  
    snajeeb shah
    Greenhorn
    Posts: 11
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks Salvin Fancis, I am trying to read the properties file to read database related information at server side. You are right I shouldn't place it on client side. Could you please let me know how should I read properties file.
     
    salvin francis
    Bartender
    Posts: 2326
    100
    Google Web Toolkit Eclipse IDE Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Well then I would suggest you do it using existing java frame work to do this for you.
    see http://www.mkyong.com/java/java-properties-file-examples/

    You can add it to a servlet. The properties file itself can be kept in a safe place such as WEB-INF folder.
     
    snajeeb shah
    Greenhorn
    Posts: 11
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I also used this technique... but It doesn't read the file.


    BufferedInputStream stream = new BufferedInputStream(DBSettings.getClass().getResourceAsStream("DBConfig.properties"))‌​;

    Properties prop = new Properties();
    prop.load(new FileInputStream("DBConfig.properties")); //prop.load gives error
     
    snajeeb shah
    Greenhorn
    Posts: 11
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    It can't read the file. I have written this code in servlet and and put the DBConfig.properties file inside it. I also tried putting the same file in WAR and META-INF directory as well. I would highly appreciate your support.

    String filename = "DBConfig.properties";

    input = DBSettings.class.getClassLoader().getResourceAsStream(filename);

    if (input == null) {
    logger.log(Level.INFO,"Sorry, unable to find "+ filename);
    return;
    }

    prop.load(input);
     
    salvin francis
    Bartender
    Posts: 2326
    100
    Google Web Toolkit Eclipse IDE Java
     
    snajeeb shah
    Greenhorn
    Posts: 11
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks Salvin Francis...

    I really appreciate you help. You support really helped. Thanks a lot
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!