2012-06-11 39 views
1

嗨,我使用GWT發送文件使用servlet。無法發送ListBox和文件在一起

最初我試圖發送文件到服務器。這工作正常。

現在在af ormPanel中我添加了3個Listbox。

private ListBox propertyNamelist = getListBox("propertyName"); 
    private ListBox propertyTypeList = getListBox("propertyType"); 
    private ListBox propertyValueList = getListBox("propertyValue"); 

private ListBox getListBox(String name){ 

      listbox = new ListBox(); 
      listbox.setName(name); 

     return listbox; 
    } 

然後它被添加到FormPanel。

formPanel.setWidget(propertyNamelist); 
formPanel.setWidget(propertyTypeList); 
formPanel.setWidget(propertyValueList); 
formPanel.submit(); 

在服務器端。

try { 

     ServletFileUpload upload = new ServletFileUpload(); 

     FileItemIterator iterator = upload.getItemIterator(request); 
     while (iterator.hasNext()) { 
      FileItemStream item = iterator.next(); 
      stream = item.openStream(); 

      if (item.isFormField()) { 
       log.warning("Got a form field: " + item.getFieldName()); 
       System.out.println(" chk fg " +item.getFieldName() +" = "+ Streams.asString(item.openStream())); 


      } else { 

       log.warning("Got an uploaded file: " + item.getFieldName() 
         + ", name = " + item.getName()); 
       fileName = item.getName(); 
       mimetype = item.getContentType(); 

      } 
     } 

    }catch (Exception e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

輸出:

WARNING: Got a form field: propertyValue 
Jun 11, 2012 11:37:55 AM com.google.apphosting.utils.jetty.JettyLogger warn 
WARNING: /UploadFileServlet: org.apache.commons.fileupload.FileItemStream$ItemSkippedException 
chk fg propertyValue = motivation 

根據我的動機是列表框PropertyValue,這裏因爲有在列表框中的多個值的第一個值。

還有更多的應該顯示的列表框。

我無法理解這種情況。

注意:我不能通過RPC發送Listbox導致這些列表框與發送到服務器和服務器到外部存儲庫的文件有關。

一些plz幫助。

回答

2

顧名思義,setWidgetFormPanel取代FormPanel小部件的內容。

你想要把幾個小部件的FormPanel裏面,這樣一箇中間容器(如FlowPanel)把你的小部件:

// put all widgets together in some container (you can have a more complex layout) 
FlowPanel container = new FlowPanel(); 
container.add(fileUpload); 
container.add(propertyNameList); 
container.add(propertyTypeList); 
container.add(propertyValueList); 

// set the container as the content of the form, so named form widgets will get 
// their value sent to the server. 
formPanel.setWidget(container); 
+0

我所有的錯誤。我只是意識到that..thanks @ThomasBroyer – GameBuilder

+0

可以幫助我這個[鏈接] [http://stackoverflow.com/q/10980022/780393] – GameBuilder