<%--
Document : newjsp
Created on : 2017-8-4, 15:18:08
Author : Administrator
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
<a id="filePicker-icon">导入数据</a>
<script type="text/javascript">
var table;
/*修改自动滚动条出现复选框无法选中的问题*/
$(function () {
/*导入数据准备*/
setUploader("filePicker-icon", "iconUrl", "${Suser.userNo}")
});
function DataImport(filePath) {
var ItemType = $("#ItemType").val();
$.ajax({
type: "POST",
url: "/tohersystem/dataimport",
data: "filePath=" + filePath + "&ItemType=" + ItemType,
async: true,
dataType: "text",
success: function (data) {
if (data == "success") {
layer.msg('导入成功!', {icon: 1, time: 1000});
setTimeout("$('#btn-refresh').click();", 1000)
} else {
layer.msg(data, {icon: 5, time: 2000});
}
}
});
}
function setUploader(pickid, returnId, userNo) {
var uploader = WebUploader.create({
auto: true,
swf: '/lib/webuploader/0.1.5/Uploader.swf',
// 文件接收服务端。
server: '/FileUpLoad?userNo=' + userNo,
// 选择文件的按钮。可选。
// 内部根据当前运行是创建,可能是input元素,也可能是flash.
//获取到按钮,当点击按钮的时候就打开查找文件,
pick: '#' + pickid,
// 不压缩image, 默认如果是jpeg,文件上传前会压缩一把再上传!
resize: false,
// 只允许选择图片文件。
});
// uploader.on是监听器,当监听到'uploadSuccess'的事件的时候,就运行 function (file, response)这个函数
uploader.on('uploadSuccess', function (file, response) {
这是'/FileUpLoad这个servlet的返回数据,格式是{“code”:“success”,“msg”:“/wenjian/lujin”}
if (response.code == "success") {
// alert("上传成功");
layer.prompt({title: '请输入管理密码'}, function (val) {
var password = val;
$.ajax({
type: "POST",
url: "tohersystem/common/checkpassword.do",
data: "password=" + password,
async: true,
dataType: "text",
success: function (data) {
if (data == "success") {
// layer.msg('密码正确', {icon: 1, time: 1000});
DataImport(response.msg);
} else {
layer.msg(data, {icon: 5, time: 1000});
setTimeout("layer.closeAll();", 500)
setTimeout("$('#btn-refresh').click()", 1000)
}
}
});
layer.close();
});
} else {
alert("上传失败");
}
});
}
</script>
</body>
</html>