• spring mvc 中Uploadify插件的使用


    具体过程不写了,直接上代码

    jsp代码

    $("#uplodefile").uploadify({
                    'swf': '/statics/uploadify/uploadify.swf',
                    'uploader': '/contacts/method11',
                    'buttonText': '选择文件',
                    'height': 20,
                    'width': 80,
                    'fileTypeDesc': 'Excel 工作表',
                    'fileTypeExts': '*.xls;*.xlsx',
                    ////'formData': { 'Action': 'UploadTopUpRecordsList' },
                    ////选择文件后自动上传
                    'auto': false,
                    ////设置为true将允许多文件上传
                    'multi': false,
                    'sizeLimit': '2048000', //最大允许的文件大小为2M
                    'displayData': 'speed', //进度条的显示方式
                    //'queueID': 'fileQueue',
                    'onUploadSuccess': funComplete //完成上传任务
                });
    <table style="margin: 0 auto;">
            <tr>
                <td style="position: relative;">
                    <input id="uplodefile" name="uplodefile" class="uploadify" type="file" />
                </td>
                <td>
                    <a href="javascript:$('#uplodefile').uploadify('upload')" class="easyui-linkbutton" >上传</a>&nbsp;&nbsp;
                    <a href="javascript:$('#uplodefile').uploadify('cancel')" class="easyui-linkbutton" >取消上传</a>
                </td>
            </tr>
        </table>
    package com.huanshare.service;
    
    import org.springframework.util.FileCopyUtils;
    import org.springframework.web.multipart.MultipartFile;
    import org.springframework.web.multipart.MultipartHttpServletRequest;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import java.io.File;
    import java.io.IOException;
    import java.text.SimpleDateFormat;
    import java.util.*;
    
    /**
     * Created by huan.liu on 2015/12/17.
     */
    @SuppressWarnings("serial")
    public class Upload extends HttpServlet {
        @SuppressWarnings("unchecked")
        public void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
    
            MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
            MultipartFile multipartFile = multipartRequest.getFile("Filedata");
            String fileName = multipartFile.getOriginalFilename();
            byte[] bytes = multipartFile.getBytes();
            String path=request.getSession().getServletContext().getRealPath("/");
            path = path + "/uploads/";
           // String savePath = "/servlet/Upload";
            File f1 = new File(path);
            System.out.println(path);
            if (!f1.exists()) {
                f1.mkdirs();
            }
    
            String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
            SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
            String newFileName = df.format(new Date()) + "_" + new Random().nextInt(1000) + "." + fileExt;
            File f2 = new File(path+newFileName);
            FileCopyUtils.copy(bytes, f2);
        }
    }

    只是一个简单的例子,自己以后学习使用

  • 相关阅读:
    Elasticsearch URI search 查询语法整理
    在linux下执行git clone、git pull 、git push等操作免密
    Gitlab 安装、升级、备份、恢复、汉化等
    python 使用xlsxwriter 写入数据时,当数据中链接的后面包含空格时(如:"http://*** "),导出问题打开报错
    offsetLeft && left
    DOM事件绑定方式
    获取不到offsetHeight问题
    jquery 图片预加载
    模仿JQuery 的添加多个事件的原理
    当节点结构变化的时候要重新获取 不然之前的变量还是以前的节点结构
  • 原文地址:https://www.cnblogs.com/myhappylife/p/5054622.html
Copyright © 2020-2023  润新知