52,798
社区成员
发帖
与我相关
我的任务
分享
id : 'UploadLogo',
autoScroll : false,
xtype : 'textfield',
fieldLabel:'本地上传',
name : 'file',
hideLabel : true,
autoCreate : {
id : 'file',
tag : "input",
type : "file",
size : "20",
autocomplete : "off",
onChange : "Ext.get('UploadLogofile').dom.value=Ext.get('file').dom.value;"
}
}
Ext.onReady(function(){
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<link rel="stylesheet" type="text/css" href="ext2.2/resources/css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="ext2.2/examples/shared/examples.css" />
<link rel="stylesheet" type="text/css" href="upload/css/Ext.ux.UploadDialog.css" />
<script type="text/javascript" src="ext2.2/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="ext2.2/ext-all-debug.js"></script>
<script type="text/javascript" src="upload/Ext.ux.UploadDialog.packed.js"></script>
<script type="text/javascript" src="upload/Ext.ux.UploadDialog.js"></script>
</head>
<script type="text/javascript">
Ext.onReady(function() {
var dialog = new Ext.ux.UploadDialog.Dialog({
title: '文件上传__上传过程中关闭窗口,不影响上传_wayfoon',
url:'uploadJSPBack.jsp',
width : 450,
height : 300,
minWidth : 450,
minHeight : 300,
draggable : true,
resizable : true,
//autoCreate: true,
constraintoviewport: true,
permitted_extensions:['JPG','jpg','jpeg','JPEG','GIF','gif','bmp','BMP'],
modal: true,
//post_var_name: 'mms',
reset_on_hide: false,
allow_close_on_upload: true //关闭上传窗口是否仍然上传文件
// upload_autostart: false //是否自动上传文件
});
dialog.show();//'show-button'
dialog.on('uploadsuccess', onUploadSuccess);
// 上传成功后的回调成功的函数
function onUploadSuccess(dialog, filename, resp_data, record)
{
alert(filename);
}
});
</script>
<body>
</body>
</html>
<%@ page language="java"
import="java.util.*,java.io.*,org.apache.commons.fileupload.*"
pageEncoding="GBK"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'uploadJSPBack.jsp' starting page</title>
<meta http-equiv="Content-Type" content="text/html; charset=GBK" />
<%
response.setCharacterEncoding("GBK");
String uploadPath = "";
String tempPath = "d:\\";
try {
System.out.println("开始进行文件上传");
DiskFileUpload fu = new DiskFileUpload();
fu.setSizeMax(4194304); // 设置最大文件尺寸,这里是4MB
fu.setSizeThreshold(4096); // 设置缓冲区大小,这里是4kb
fu.setRepositoryPath(tempPath); // 设置临时目录
List fileItems = fu.parseRequest(request); // 得到所有的文件:
Iterator i = fileItems.iterator();
// 依次处理每一个文件:
while (i.hasNext()) {
FileItem fi = (FileItem) i.next();
String fileName = fi.getName();// 获得文件名,这个文件名包括路径:
if (fileName != null) {
// 在这里可以记录用户和文件信息
// 此处可以定义一个接口(CallBack),用于处理后事。
// 写入文件a.txt,你也可以从fileName中提取文件名:
String name = fileName.substring(0, fileName
.indexOf("."));
String extfile = fileName.substring(fileName
.indexOf("."));
//上传时间作为文件名,用以防止重复上传
//Timestamp now = new Timestamp((new java.util.Date()).getTime());
//SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMddHHmmssSSS");
//String pfileName= fmt.format(now).toString().trim();
System.out.println(name + extfile);
fi.write(new File(name + extfile));
}
}
System.out.println("上传成功");
response.setContentType("text/html;charset=utf-8");
response.getWriter().print("{success:true,message:'上传成功'}");
// 跳转到上传成功提示页面
} catch (Exception e) {
e.printStackTrace();
response.getWriter().print("{success:false,message:'上传失败'}");
// 可以跳转出错页面
}
%>
</head>
<body>
</body>
</html>