ExtJS+Struts2文件上传,来向大神们求救了
我要实现从从页面提交三个文件(一个mp3,一个txt,一个photo),服务器Struts接收,各种异常啊,上代码
1,ExtJS代码
var addFormPanel = Ext.widget({
xtype: 'form',
bodyPadding: '5 5 0',
url:'scenery/add_radio',
fileUpload:true,
forceFit:true,
fieldDefaults: {
labelAlign: 'top',
msgTarget: 'side'
},
items: [{
xtype: 'container',
layout: 'hbox',
anchor: '100%',
items:[{
xtype: 'container',
flex: 1,
layout: 'anchor',
items: [{
xtype: 'filefield',
name: 'radio',
fieldLabel: '音频文件mp3',
allowBlank: false,
anchor: '95%',
buttonText: '浏览'
},{
xtype: 'textfield',
fieldLabel: '音频名称',
name: 'radioPojo.radioName',
anchor: '95%',
allowBlank: false
},{
xtype: 'textfield',
fieldLabel: '音频时长',
name: 'radioPojo.radioLength',
anchor: '95%',
regex:/^([0-5][0-9]):([0-5][0-9])$/,
regexText:'请输正确的时间格式MM:ss',
allowBlank: false
},{
xtype: 'filefield',
fieldLabel: '音频字幕',
name: 'lyric',
anchor: '95%',
allowBlank: false,
buttonText: '浏览'
}]
},{
xtype: 'container',
flex: 1,
layout: 'anchor',
items: [{
xtype: 'combobox',
fieldLabel: '对应的图片:选择提交方式',
name: 'pic_option',
anchor: '95%',
emptyText:'请选择...',
store:pstore,
queryMode: 'local',
displayField: 'value',
valueField: 'key',
tiggerAction:'all',
anchor:'95%',
listeners:{
select : function(combo, record, index){
if(combo.value==0){
Ext.getCmp('local_photo').show().enable();
Ext.getCmp('local_name').show().enable();
}else if(combo.value==1){
Ext.getCmp('local_photo').hide().disable();
Ext.getCmp('local_name').hide().disable();
choose_image();
}
}
}
},{
xtype: 'filefield',
name: 'picture',
fieldLabel: '图片文件',
id:'local_photo',
anchor: '95%',
allowBlank: false,
hidden:true,
disabled:true,
buttonText: '浏览'
},{
xtype: 'textfield',
fieldLabel: '图片名称',
id:'local_name',
name: 'picturePojo.pictureName',
anchor: '95%',
allowBlank: false,
hidden:true,
disabled:true,
},{
xtype: 'hiddenfield',
name: 'radioPojo.radioSceneryId',
value: sceneryNo
}]
}]
}],
buttons: [{
text: '保存',
iconCls:"submit",
handler: function() {
var form = this.up('form').getForm();
if (form.isValid()) {
form.submit({
waitTitle: '请稍后',
waitMsg : '正在上传文件...',
success: function(form, action) {
Ext.Msg.alert('提示', "新增成功");
addWin.close();
scenery_store.reload();
},
failure: function(form, action) {
warn('新增失败,请稍后重试!');
}
});
};
}
},{
text: '关闭',
iconCls:"close",
handler: function() {
addWin.close();
}
}]
});
import java.io.File;
import org.springframework.beans.factory.annotation.Autowired;
import com.opensymphony.xwork2.ActionSupport;
import com.yuansheng.bicycle.entity.Picture;
import com.yuansheng.bicycle.entity.Radio;
import com.yuansheng.bicycle.service.SceneryRadioAndPictureService;
public class AddRadioAndPictureAction extends ActionSupport{
@Autowired
private SceneryRadioAndPictureService sceneryRadioAndPictureServiceImpl;
private File radio;
private File picture;
private File lyric;
private String radioFileName;
private String radioContentType;
private String pictureFileName;
private String pictureContentType;
private String lyricFileName;
private String lyricContentType;
private Radio radioPojo;
private Picture picturePojo;
private String pic_option;
private boolean success;
@Override
public String execute() throws Exception {
success=sceneryRadioAndPictureServiceImpl.handle(radio,picture,pictureFileName,lyric,radioPojo,picturePojo,pic_option);
return "json_result";
}
getter和setter省略
}