ExtJs4+struts2文件上传后弹出下载框
ExtJs4.2+struts2文件上传成功后,弹出下载框没有回调函数。
js代码:
createUploadWindow: function(config) {
var form1 = new Ext.FormPanel({
//id:'addFileBase-form',
baseCls: 'x-plain',
defaultType: 'textfield',
labelWidth :80,
fileUpload : true,
autoDestroy :true
});
var winTitle = '图片上传';
this.winHeight = 170;
this.winWidth = 400;
var btns = [];
form1.add(this.createResourceFileAddButtonFieldset(config));
form1.doLayout();
//
btns.push({
text: '上传',
listeners : {
'click': function(){
var fm = form1.getForm();
if(fm.isValid()) {
if(Ext.getCmp('upload').getValue() == ''){
Ext.Msg.alert('提示','请上传图片');
return;
}
var fileName = Ext.getCmp('upload').getValue();
fileName = fileName.substring(fileName.lastIndexOf('\\')+1,fileName.length);
if(!this.isChinese(fileName)){
alert('图片中不能包含中文');
return;
}
fm.submit({
url : UrlController.getUrl("addFile"),
method : 'POST',
type:'ajax',
scope:this,
success : function(fp, o) {
alert('成功');
win.close();
},
failure : function(fp,o) {
Ext.Msg.alert('Error',
'失败');
win.close();
}
})
}
},
scope:this
}
});
btns.push({
text: '取消',
handler: function(){
win.close();
}
});
var win = new Ext.Window(
Ext.applyIf(config||{}, {
minimizable : false,
maximizable : true,
resizable: false,
layout: 'fit',
modal: true,
width: this.winWidth,
height: this.winHeight,
bodyStyle:'padding:5px;',
items: form1,
buttons: btns,
stateful :false,
title: winTitle
})
);
win.show();
},
createResourceFileAddButtonFieldset: function(config) {
var fieldSet = new Ext.ux.FieldSet({
style:"margin-top: 5px;",
autoHeight:true,
defaults: { width : 230 }
});
var files = new Ext.form.field.File({
id:'upload',
name : 'upload',
buttonText:'选择图片',
regex:/^.+\.(jpg|png|gif|bmp)$/,
regexText:"你只能选择jpg,png,gif,bmp格式的图片",
anchor : '100%' // anchor width by percentage
});
var manuCode = new Ext.form.Hidden({
id: 'code',
name:'code',
value:config.code
});
fieldSet.title = '图片上传';
fieldSet.add(manuCode);
fieldSet.add(files);
return fieldSet;
}
private File upload;
private String uploadFileName;
public File getUpload() {
return upload;
}
public void setUpload(File upload) {
this.upload = upload;
}
public String getUploadFileName() {
return uploadFileName;
}
public void setUploadFileName(String uploadFileName) {
this.uploadFileName = uploadFileName;
}
/**
* 上传文件
* @return
*/
public String addFile() {
String result = "";
try {
if (upload != null) {
File uploadFile = upload;
int fileType = FileMd5Util.getFileType(uploadFileName);
StringBuffer sb = new StringBuffer();
//获取摘要
String zhaiyao = FileMd5Util.getFileMD5String(uploadFile);
sb.append(zhaiyao).append("_");
if (fileType == 1) {//若为图片
Image image = ImageIO.read(uploadFile);
sb.append(image.getWidth(null)).append("X").append(image.getHeight(null)).append("_");
}
uploadFileName = uploadFileName.replaceAll("_", "");
String dirPath = getText("product.pic.rootdir") + code;
sb.append(uploadFileName);
File dirFile = new File(dirPath);
if (!dirFile.exists()) {
dirFile.mkdirs();
}
if (dirFile.exists() && dirFile.isDirectory()) {
File destFile = new File(dirFile, sb.toString());
FileUtils.copyFile(uploadFile, destFile);
result = "{success:true}";
} else {
result = "{success:false,'message':'目录不存在'}";
}
} else {
result = "{success:false,'message':'未找到导入文件'}";
}
outAddFile(result);
} catch (Exception e) {
logger.opBusinessWarLogger("addFile:", e);
result = "{success:false,'message':'导入文件异常'}";
try {
outAddFile(result);
} catch (Exception e1) {
logger.opBusinessWarLogger("addFile:", e1);
}
}
return NONE;
}
/**
* 向页面输出JSONObject对象
*
* @param obj
* @throws IOException
*/
@SuppressWarnings("deprecation")
public void outAddFile(String result) throws IOException {
HttpServletResponse resp = ServletActionContext.getResponse();
resp.setContentType("text/html; charset=UTF-8");
PrintWriter pw = resp.getWriter();
pw.print(result);
//pw.close();
}
[解决办法]
你return NONE了。NONE对应的是什么