문제

I want to make a browse file form in my GWT application and i use the uploadfile form so i can browse files with browsers, but with uploadfile i can get only the file name.

Could someone tell me how to retrieve the full path of the file after choosing a file on the file browser? Is there a servlet that returns the full path or there is another way besides the uploadfile form.

도움이 되었습니까?

해결책

Here what you are looking for is to upload a file using GWT/GXT form panel right?. There is no need to get the full path of the file or use the name to do this task. You can achieve this doing following

1.Hope you already added the FormPanel correctly check whether you specified these properties

   final FormPanel fp = new FormPanel();
   fp.setAction("url which handles file uploads");
   fp.setEncoding(Encoding.MULTIPART);
   fp.setMethod(Method.POST);

2.Implement a servlet which handles the POST requests and read the file data from the request. you can easily use guava or apache commons file utilities for this purpose.

3.Configure the file upload servlet mappings in web.xml (for production mode) or if you want to use it in dev mode add the same mapping in yourmodule.gwt.xml as well. ex:

 <servlet path="/<path to servlet>" class="<fully-qualified class name of servlet>"/>

4.Handle the file submission complete event by adding a handler to form panel

fp.addSubmitCompleteHandler(new SubmitCompleteHandler() {
      public void onSubmitComplete(SubmitCompleteEvent event) {
       //event handling
      }
    });

By the way, I found a nice library which does multi file uploads. https://code.google.com/p/gxt-multi-upload/

Hope this will help.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top