Extjs 文件上传
2009-11-13 16:33
274 查看
支持多文件上传,解决中文乱码问题。
废话少说,直接贴上代码:
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/
废话少说,直接贴上代码:
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/
相关文章推荐
- Extjs4 + springMVC的文件上传
- ExtJS:文件上传实例
- Extjs4---文件上传,后台struts2
- Extjs文件上传
- Extjs实现文件上传
- Extjs 扩展Htmleditor,支持 图片上传 文件上传 插入flash 插入多媒体 插入层 插入横线等功能
- EXTJS文件上传点提交是报如下错误:missing ) in parenthetical
- ExtJS4 上传文件类型和大小的判断方法(实例)
- asp.net mvc + ExtJs 上传文件
- ExtJS+Jquery实现文件上传
- Extjs 文件上传
- jsp+Extjs实现动态显示文件上传进度
- EXTjs 同时支持文件上传和图片上传的htmleditor
- extjs+springmvc上传文件显示进度条
- ExtJS fileupload组件上传文件后从服务端解析JSON格式数据
- ExtJS + fileuploadfield上传文件代码
- 【Extjs】上传文件
- extjs 上传文件 fileUpload
- 利用jsp+Extjs实现动态显示文件上传进度
- extjs与struts2整合实现文件上传之经历