2012-08-28 31 views
1

我從客戶端使用java servlet獲取參數。 這是我的帖子:如何用Java解析請求?

enter image description here

發送請求到服務器我使用ExtJS的:

var x = new Ext.Window({ 
           title:'Загрузка файла', 
           items:[ 
            formp = new Ext.FormPanel({ 
             fileUpload: true, 
             width: 350, 
             autoHeight: true, 
             bodyStyle: 'padding: 10px 10px 10px 10px;', 
             labelWidth: 70, 
             defaults: { 
              anchor: '95%', 
              allowBlank: false, 
              msgTarget: 'side' 
             }, 
             items:[{ 
              xtype:"combo", 
              fieldLabel:'Тип файла ', 
              name:"cb_file", 
              id:"cb_file", 
              mode:"local", 
              typeAhead: false, 
              loadingText: 'Загрузка...', 
              store:new Ext.data.SimpleStore({ 
               fields: ['file_name', 'file_type'], 
                data : [['*.MIF/MID', 'mif'],['*.GPX', 'gpx']] 
               }), 
              forceSelection:true, 
              emptyText:'выбирите тип...', 
              triggerAction:'all', 
              valueField:'file_type', 
              displayField:'file_name', 
              anchor:'60%' 
             },{ 
              xtype: 'fileuploadfield', 
              id: 'filedata', 
              emptyText: 'Выберите файл для загрузки...', 
              fieldLabel: 'Имя файла', 
              buttonText: 'Обзор' 
             }], 
             buttons: [{ 
              text: 'Загрузить', 
              handler: function(){ 
               mapinfo="mapinfo"; 
                formp.getForm().submit({ 
                 url: url_servlet+'uploadfile', 
                 //params: {file_type: mapinfo}, 
                 success: function(formp, o) { 
                  alert(o.result.file); 
                  alert(o.result.success); 
                  kad_tab.getStore().reload() 
                  zoom_store.load(); 
                  } 
                }) 
              } 
             }] 
            }) 
           ] 
          }) 
          x.show(); 

如果我理解這個正確:發送2個參數到服務器cb_filefiledata後。我試圖讓他們通過:

String st = request.getParameter("cb_file"); 

但是得到空。

當我試圖讓該文件:

list = upload.parseRequest(request); 

我得到null爲好。
但如果我只發送文件(爲此我刪除行與組合框)它工作正常。
如何解析此請求?

回答

1

這是因爲請求是一個多部分。您可以閱讀請求流併爲自己解析它,或者使用Apache Commons(請使用這個!)。

在這裏,你有ilustrate怎麼做你想要Apache Commons fileupload做什麼sniplet:

​​

祝你好運!