我有个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}
你用application/x-www-form-urlencoded
传输FileUpload文件上传时肯定不行啊,你得设置 multipart/form-data, 这样不论是文本还是文件都可以的,不过在Ext中怎么设置成multipart/form-data 你自己找一下。
不懂。。。。是不是因为默认的参数类型是text,所以文件没上传上去
[code="java"]items: [{
xtype:'fieldset',
title: 'Script Load',
collapsible: true,
autoHeight:true,
defaults: {width: 210},
defaultType: 'textfield',[/code]
http://kangsoft.iteye.com/blog/677773
楼主看一下这个
[code="java"]
upload = Ext.extend(Ext.Window,{
title : '批量导入',
width : 350,
height : 80,
autoHeight : true,
modal : true,
collapsible : true,
frame : true,
resizable : false,
buttonAlign : 'center',
initComponent : function(){
Ext.apply(this,{
items : [{
xtype : 'form',
id : 'form',
labelWidth : 70,
labelAlign : 'right',
border : false,
fileUpload : true,
baseCls : 'x-plain',
bodyStyle : 'padding : 5px 5px 0',
defaults : {
anchor : '100%',
magTarget : 'side'
},
items : [{xtype : 'textfield',inputType : 'file',name:'upload',fieldLabel : '文件上传'}]
}]
});
upload.superclass.initComponent.apply(this,arguments);
}
});
[/code]