weizhouyue 2011-11-23 22:28
浏览 260
已采纳

FileUploadField 选择了一个文件,传到struts2的Action中,显示为null, 是什么问题?

我有个formpanel, 里面有个FileUploadField,选择一个文件后,传到struts2的Action中,但是从调试的显示中看到参数没有传过去,响应的结果为null.

我想请大家帮我看看代码怎么改,多谢了

 

MyDesktop.ScriptWindow = Ext.extend(Ext.app.Module, {
    id:'script-win',
    init : function(){
        this.launcher = {
            text: 'Script Selection',
            iconCls:'tabs',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('script-win');
        if(!win){
            win = desktop.createWindow({
                id: 'script-win',
                title:'Script Selection',
                width:400,
                height:450,
                iconCls: 'tabs',
                shim:false,
                animCollapse:false,
                border:false,
                constrainHeader:true,
                layout: 'fit',
                items: new Ext.FormPanel({
         id:'script',
      labelWidth: 70,
      frame:true,
      bodyStyle:'padding:5px 5px 0',
      width: 350,


      items: [{
       xtype:'fieldset',
       title: 'Script Load',
       collapsible: true,
       autoHeight:true,
       defaults: {width: 210},
       defaultType: 'textfield',
       
       items :[new Ext.ux.form.FileUploadField({
        id: 'upload',
        name: 'upload',
        emptyText: '',
        fieldLabel: 'Script',
        allowBlank:false,
        buttonText: '',
        buttonCfg: {
         iconCls: 'tabs'
        }
       }),
       new Ext.form.ComboBox({
        id: 'mobile',
        name:'mobile',
        triggerAction:'all',
        fieldLabel: 'Phone',
        store: store,
        displayField: 'imsi',
        valueField: 'ip',
        mode:'local',
        allowBlank:false,
        emptyText: 'Select a phone'
       })
       ],
       buttons: [{
        type: 'submit',
        text: 'Associate',
        handler:function(){
         //Ext.Msg.alert("success", Ext.getCmp('upload').getValue());
         
         if(Ext.getCmp('script').getForm().isValid()){
          Ext.getCmp('script').getForm().doAction("submit",{
           url:"scriptLoad.action",
           method:"post",
           success:function(form,action){
            Ext.Msg.alert("Success",action.result.message);
           },
           failure:function(form, action){
            Ext.Msg.alert("Failer",action.result.message);
           }
          })
         }
        }
       },{
        text: 'Cancel',
        handler: function(){
         Ext.getCmp('upload').reset();
         Ext.getCmp('mobile').reset();
        }
       }]
      },
      {
       xtype:'fieldset',
       title: 'Script View',
       collapsible: true,
       height:250,
       labelWidth: 2,
       items : new Ext.form.TextArea({
        xtype:'textarea',
        name: 'script',
        anchor: '100% 100%',
        disabled: true,
        value:'loop->1:100, CALL -> <TO_BE_DEFINED>:5,  SLEEP -> 2000, END LOOP -> ID=1'
       })
      }]  
    })
            });
        }
        win.show();
    }
});

 

LoadScriptAction.java

public class LoadScriptAction extends ActionSupport{
 private File upload;
 private String uploadContentType;
 private String uploadFileName;
 private String mobile;
 private String message;
 
 public String getMessage() {
  return message;
 }
 public void setMessage(String message) {
  this.message = message;
 }
 public File getUpload() {
  return upload;
 }
 public void setUpload(File upload) {
  this.upload = upload;
 }
 public String getUploadContentType() {
  return uploadContentType;
 }
 public void setUploadContentType(String uploadContentType) {
  this.uploadContentType = uploadContentType;
 }
 public String getUploadFileName() {
  return uploadFileName;
 }
 public void setUploadFileName(String uploadFileName) {
  this.uploadFileName = uploadFileName;
 }
 public String getMobile() {
  return mobile;
 }
 public void setMobile(String mobile) {
  this.mobile = mobile;
 }
 
 public String execute() throws Exception{
  message = this.uploadFileName + " " + this.mobile;
  return SUCCESS;
 }
}

<struts> 
    <include file="struts-default.xml"/>  
        
    <package name="script" extends="json-default"> 
        <action name="scriptLoad" class="android.action.LoadScriptAction"> 
            <result type="json"/> 
        </action>  
    </package>
 
</struts> 

 

调试显示: (我要传两个参数过去,一个是我选择的文件,一个是mobile的号码。为什么这里只显示传了一个参数过去?)

 

参数application/x-www-form-urlencoded
mobile 0610550020
源代码
mobile=0610550020

 

响应:

{"message":"null 0610550019","mobile":"0610550019","upload":null,"uploadContentType":null,"uploadFileName":null}
  • 写回答

4条回答 默认 最新

  • jiangguangxian 2011-11-24 08:36
    关注

    你用application/x-www-form-urlencoded
    传输FileUpload文件上传时肯定不行啊,你得设置 multipart/form-data, 这样不论是文本还是文件都可以的,不过在Ext中怎么设置成multipart/form-data 你自己找一下。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?