百度上傳文件到寫入數據庫之一

<%-- 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>
相關文章
相關標籤/搜索