打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Extjs和struts2 做的上传
Extjs和struts2 做的上传
2011年06月01日 星期三 15:07

业务要求是这样的:从本地选择一个excel文件,服务器端解析该文件,并显示到页面上。思路是先将该excel文件上传,然后读取内容填充到页面上。

form的写法(去掉验证之类不必要的):

var uploadForm =new Ext.form.FormPanel({

id:'_form',

labelAlign:'right',

frame:true,

height:100,

width:380,

fileUpload:true,

items:[

{

id:'filepath2',

xtype:'textfield',

width:260,

height:20,

fieldLabel:'Excel文件',

name:'attachment',

inputType:'file'

}

]

,

buttons:[

{

text:'导入',

handler:function(){

var p = Ext.getCmp('filepath2').getValue();

p = './Food/foodSchool_uploadFile.action?path=' + p;

p = p.replace(/\\/g,'$');

if(uploadForm.getForm().isValid()){

uploadForm.getForm().url = p;

uploadForm.getForm().submit({

waitMsg: '请稍等...',

success:function(){

var conn = new Ext.data.Connection();

conn.request({// 发送异步请求

url : './Food/foodSchool_importReport.action',

method : 'POST',//注意大写

params : {

'path' : p

},

success : function(rsp, opt) {

//导入成功后,利用AJAX执行另一个方法读取excel文件,并显示到页面上

......

},

failure : function(rsp, opt) {

Ext.Msg.alert('异常', '导入失败,请重新选择Excel文件!');

}

});

win2.hide();

},

failure:function(){

Ext.Msg.alert('提示','导入失败!');

}

});

}

}

}

]

});

 

按钮的写法:

var btn2 = new Ext.Button({

text:'导入',

handler:function(){

win2 = win2 || new Ext.Window({

id:'uploadFile2',

title:'选择导入的文件',

modal:true,

width:400,

height:150,

closeAction:'hide',

layout:'fit',

resizable:false,

items:uploadForm 

});

win2.show();

}

});

 

后台:

public String uploadFile() {

try {

HttpServletRequest request = ServletActionContext.getRequest();

String path = request.getParameter("path");

path = new String(path.getBytes("ISO-8859-1"),"utf-8");

String projectPath = request.getSession().getServletContext().getRealPath("\\");

String fileName = path.substring(path.lastIndexOf("$") + 1);

String newFilePath = projectPath + "warnning\\security\\food\\uploadTemp\\" + fileName;

newFilePath = newFilePath.replaceAll("\\\\", "\\\\\\\\");

 

File uploadedFile = new File(newFilePath);

FileUtils.copyFile(this.attachment, uploadedFile);


} catch (Exception e) {

e.printStackTrace();

}

return null;

}

至此结束

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Extjs学习总结之23EditGridPanel可编辑表格
ExtJs之combobox详解
extjs [文本编辑器:Editor]
ExtJS专题
Extjs 下拉grid
ExtJs4学习笔记(五) comboBox使用方法及扩展
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服