Extjs 文件上传
来源:互联网 发布:大连软件职业学院学费 编辑:程序博客网 时间:2024/05/21 20:31
支持多文件上传,解决中文乱码问题。
废话少说,直接贴上代码:
html代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>upload</title>
<link rel="stylesheet" type="text/css"
href="jslib/ext3.0/resources/css/ext-all.css" />
<script type="text/javascript"
src="jslib/ext3.0/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="jslib/ext3.0/ext-all.js"></script>
<script type="text/javascript"
src="jslib/ext3.0/src/locale/ext-lang-zh_CN.js"></script>
<link rel="stylesheet" type="text/css"
href="jslib/ext3.0/examples/form/file-upload.css" />
<script type="text/javascript"
src="jslib/ext3.0/examples/ux/FileUploadField.js"></script>
<script type="text/javascript" src="js/Upload.js"></script>
</head>
<body>
<div id="fi-form"></div>
</body>
</html>
js代码:
Ext.onReady(function(){
Ext.QuickTips.init();
var msg = function(title, msg){
Ext.Msg.show({
title: title,
msg: msg,
minWidth: 200,
modal: true,
icon: Ext.Msg.INFO,
buttons: Ext.Msg.OK
});
};
var fp = new Ext.FormPanel({
renderTo: 'fi-form',
fileUpload: true,
width: 300,
frame: true,
title: 'File Upload Form',
autoHeight: true,
bodyStyle: 'padding: 10px 10px 0 10px;',
labelWidth: 60,
defaults: {
anchor: '95%',
allowBlank: false,
msgTarget: 'side'
},
items: [{
xtype: 'fileuploadfield',
id: 'form-file',
autoWitdh:true,
emptyText: '',
fieldLabel: '上传文件',
name: 'photo-path',
buttonText: '',
buttonCfg: {
iconCls: 'upload-icon'
}
}],
buttons: [{
text: '上传',
handler: function(){
if(fp.getForm().isValid()){
fp.getForm().submit({
url: 'jsplib/upload.jsp',
waitMsg: '文件上传中,请等待',
success: function(fp, o){
o=Ext.util.JSON.decode(o);
msg(o.flag, o.file);
},
failue:function(){
alert("上传失败");
}
});
}
}
},{
text: '取消',
handler: function(){
fp.getForm().reset();
}
}]
});
});
jsp代码:
<%@page import="org.json.JSONObject"%>
<%@page import="java.io.*"%>
<%@page import="java.util.*"%>
<%@page import="com.jspsmart.upload.*"%>
<%@page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
JSONObject result = new JSONObject();
int count = 0;
String fileName = "";
SmartUpload mySmartUpload = new SmartUpload();
try {
mySmartUpload.initialize(config, request, response);
mySmartUpload.upload();
for (int i = 0; i < mySmartUpload.getFiles().getCount(); i++) {
com.jspsmart.upload.File myfile = mySmartUpload.getFiles()
.getFile(i);
fileName = myfile.getFileName();
count = mySmartUpload.save("upfile/");
}
result.put("flag", true).put("file", fileName);
} catch (Exception e) {
result.put("flag", false).put("file", fileName);
}
out.write(result.toString());
%>
所需要的jar在:
http://benbenkui.download.csdn.net/
- 【ExtJs】ExtJs的文件上传
- Extjs 文件上传
- extjs 上传文件 fileUpload
- ExtJs + Struts2文件上传
- extjs 上传文件 fileUpload
- extjs 文件上传
- Extjs实现文件上传
- extjs实现文件上传
- Extjs文件上传例子
- Extjs文件上传
- Extjs文件上传
- extjs文件上传
- Extjs 实现文件上传
- extjs文件上传
- extjs的文件上传
- ExtJS:文件上传实例
- 【Extjs】上传文件
- extjs 上传文件 fileUpload
- 主题:从jQuery看JavaScript
- VB有哪些比較簡單的入門書籍呢?
- Spring Management Console的设想
- 函数指针
- 获取客户端及服务器的信息
- Extjs 文件上传
- php调用mysql存储过程返回多个结果集的处理
- 汉字编码
- 阻止Windows注消 (log off or logging off)
- 实现PROXY穿越(1):流程和NTLM算法
- 适配器模式和外观模式
- 爱情的警示,真让人伤心哦
- 别写代码了 优秀网站源码、编程源码下载网站大集中
- DML Error Logging in Oracle 10g