百度上传文件到写入数据库之一

本文介绍了一个JSP页面的实现细节,包括如何使用WebUploader进行文件上传,并通过Ajax调用后端接口实现数据导入。文章还展示了如何处理上传后的文件路径,以及在导入数据前进行密码验证的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<%-- 
    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>

 

转载于:https://www.cnblogs.com/itchenfirst/p/7285407.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值