1

I'm using Java 1.6 with GWT 2.4.

I'm very well aware that we can get current working directory in Java using the following code:

System.getProperty("user.dir");

But GWT won't allow me to use System class at client side.

So my question is: Is there any way to get the current working directory path in GWT?

RAS
  • 8,100
  • 16
  • 64
  • 86
  • i am curious to know, why you require this ? – ajduke Apr 15 '13 at 07:52
  • Can you mention the what you intend to achieve with this data. We can provide suggestion based on that. – appbootup Apr 15 '13 at 07:58
  • @zzzz, Thanks for replying but that question is for current URL in browser. I'm asking for current directory... – RAS Apr 15 '13 at 07:59
  • 1
    @ajduke My requirement is, I need to show an image on my app dashboard. I'm deploying the app in Jboss 7.1. The path of the image would be like \jboss-as-7.1.1.Final\standalone\data\files\1.png. So in coding how should I handle this? – RAS Apr 15 '13 at 08:03

4 Answers4

0

You can write a new service (in your RemoteService/RemoteServiceImpl) which will basically get the current working directory using System.getProperty("user.dir"); ?

Its a work-around, cause GWT (client) code doesn't have javascript replacement for java.lang.System class OR i guess they don't have previlidge to read System properties (since they run on browser)

sanbhat
  • 17,522
  • 6
  • 48
  • 64
0
  1. You would need to use RPC call or RequestBuilder call.
  2. Pass the parameter the image name to the server
  3. In the service class on server side calculate the system path and return back the path information.

GWT compiles to javascript and is executed in the browser communicating with a server over http and hence cannot execute server side java code like System.getProperty("user.dir"); .

Any such requirement should be achieved via Asynchronous call to the Server.

Note: It still does not make sense to display the file system path to the user unless you are writing a System Explorer with Web GUI ( might raise some security related queries !!!)

appbootup
  • 9,537
  • 3
  • 33
  • 65
  • 1
    Thanks for the reply but I'm not showing file system path to the User. Can you tell why do you think so? – RAS Apr 15 '13 at 08:47
  • I could not think of any other need on the client side to show file system path. Even for downloading the image for the user in browser it just requires relative path from webapp context. I am curious now as to why on your side of the requirement :) – appbootup Apr 16 '13 at 03:24
  • Got it. You are hosting your image files in non-webapp context i.e not in the war deploying your GWT. Am i right? – appbootup Apr 16 '13 at 07:15
0
Current Directory in GWT.

your all java script in on client side so,there is no matter of current directory.

System.getProperty("user.dir");

Due to security reasons javascript doesn't have access to the system drives to avoid syber attacks

http://en.wikipedia.org/wiki/JavaScript#Security

see Opening a file in local file system in javascript

Inorder to get the file you need to make a server call.

Community
  • 1
  • 1
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
0

System.getProperty("user.dir") worked for me fine in GWT 2.6.1, both when running locally and when deployed to Google App Engine (where it returned e.g. /base/data/home/apps/s~rhezivt28/1.379778380561169345).

gherson
  • 169
  • 2
  • 9