zoukankan      html  css  js  c++  java
  • 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);
        }
    }

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

  • 相关阅读:
    java 实现Queue
    java 实现stack
    为什么现货白银/现货原油的报价每个交易所都不一样?
    现货交易入门之常用术语
    现货操盘手精髓语录
    现货电子交易中实物交割的概念和作用?
    关于ios对rtsp格式的流媒体支持的一些官方说明
    ProgressBar的Indeterminate属性
    安卓适配问题
    推送原理
  • 原文地址:https://www.cnblogs.com/myhappylife/p/5054622.html
Copyright © 2011-2022 走看看