Can't read property file on Server side with GWT

Xerox Shah

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.

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

Thanks in advance.

user3909865

GWT.Create can be used only in client mode. Are you sure that code execute in server side?

If i write in my application GWT.Create in server side i get this error:

java.lang.UnsupportedOperationException: ERROR: GWT.create() is only usable in client code! It cannot be called, for example, from server code. If you are running a unit test, check that your test case extends GWTTestCase and that GWT.create() is not called from within an initializer or constructor.

You can read a properties files in java. The file is similar that Constants files in GWT. Example of Properties file:

key = value host = 127.0.0.1 port = 80 username = guest password = guest

EOF

You can read this file, see the next code:

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

String fileToRead = "MY_PATH"+File.separator+"MY_FILE.properties";
Properties prop = new Properties();
try {
    File propertiesFile = new File(fileToRead);
    prop.load(new FileInputStream(propertiesFile));
    String host = prop.getProperty("host");
    String port = prop.getProperty("port");
    String username = prop.getProperty("username");
    String password = prop.getProperty("password");

    System.out.println(host);
    System.out.println(port);
    System.out.println(username);
    System.out.println(password);
} catch (FileNotFoundException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}

If the key doesnt exists getProperty(String key) return null. You can use prop.containsKey(String key); to see if the key exists. This function return a boolean (True if exists False in other case).

Greetings

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

I Can't read from the server-side socket

From Dev

Why I can't get selected file on server side?

From Dev

Can't open the excel file after generating it on server side

From Dev

Why I can't get selected file on server side?

From Dev

Drop file, files property can't read on undefined

From Dev

Can't read property of length undefined for last value read from file

From Dev

Can't decrypt file, which was encrypted on server side with OpenSSL AES 256 CBC

From Dev

Can't decrypt file, which was encrypted on server side with OpenSSL AES 256 CBC

From Dev

FlaskApp Running with Apache unable to save file on server side can't get permission to work out?

From Dev

Why can't server side and client side scripts interact?

From Dev

Can't Read *.ttf File

From Dev

Can't Read *.ttf File

From Dev

Can't read json file

From Dev

can't read a file in python

From Dev

Can't read property length of undefined - AngularJS

From Dev

Can't Read property innerHTML Javascript

From Dev

Can't read property length of undefined - AngularJS

From Dev

JavaScript - Can't read property of undefined

From Dev

Javascript can't read property of undefined

From Dev

Why can't this JSON property be read?

From Dev

TypeError: Can't read property 'map' of undefined when component uploads a file in React

From Dev

Server is not accepting connection from Client side to read data from a file

From Dev

Can people read server side node.js?

From Dev

GWT 2.7.0 Super Dev Mode, don't recompile server side code after change

From Dev

Can't catch file upload at server side using HTML5 File API and ASP.NET MVC4

From Dev

GWT - server-side synchronized block

From Dev

GWT - server-side synchronized block

From Dev

GWT Create a sub-process in server side

From Dev

dates change between client and server side (GWT)

Related Related

  1. 1

    I Can't read from the server-side socket

  2. 2

    Why I can't get selected file on server side?

  3. 3

    Can't open the excel file after generating it on server side

  4. 4

    Why I can't get selected file on server side?

  5. 5

    Drop file, files property can't read on undefined

  6. 6

    Can't read property of length undefined for last value read from file

  7. 7

    Can't decrypt file, which was encrypted on server side with OpenSSL AES 256 CBC

  8. 8

    Can't decrypt file, which was encrypted on server side with OpenSSL AES 256 CBC

  9. 9

    FlaskApp Running with Apache unable to save file on server side can't get permission to work out?

  10. 10

    Why can't server side and client side scripts interact?

  11. 11

    Can't Read *.ttf File

  12. 12

    Can't Read *.ttf File

  13. 13

    Can't read json file

  14. 14

    can't read a file in python

  15. 15

    Can't read property length of undefined - AngularJS

  16. 16

    Can't Read property innerHTML Javascript

  17. 17

    Can't read property length of undefined - AngularJS

  18. 18

    JavaScript - Can't read property of undefined

  19. 19

    Javascript can't read property of undefined

  20. 20

    Why can't this JSON property be read?

  21. 21

    TypeError: Can't read property 'map' of undefined when component uploads a file in React

  22. 22

    Server is not accepting connection from Client side to read data from a file

  23. 23

    Can people read server side node.js?

  24. 24

    GWT 2.7.0 Super Dev Mode, don't recompile server side code after change

  25. 25

    Can't catch file upload at server side using HTML5 File API and ASP.NET MVC4

  26. 26

    GWT - server-side synchronized block

  27. 27

    GWT - server-side synchronized block

  28. 28

    GWT Create a sub-process in server side

  29. 29

    dates change between client and server side (GWT)

HotTag

Archive