国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

Uploadify文件上傳

2019-11-15 00:04:26
字體:
供稿:網(wǎng)友
Uploadify文件上傳

一、簡介

  Uploadify 是一種基于html5 或 Flash的多文件上傳的jQuery插件。Uploadify可以支持多種定制。它是一種異步的文件上傳插件。下載網(wǎng)站為http://www.uploadify.com/。這里使用的是Uploadify Version 3.2.1版本。下載解壓后,目錄如下所示:

  使用Uploadify需要加入如下js

<script src="jquery1.10.2 .min.js" type="text/javascript"></script> <!-- 這里jquery 版本問1.10.2 --><script src="jquery.uploadify.min.js" type="text/Javascript"></script><link rel="stylesheet" type="text/CSS" href="uploadify.css"> <!-- 樣式文件 -->

二、示例

  網(wǎng)頁示例如下:

  1 <%@ page contentType="text/html; charset=UTF-8"%>  2 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" 

  下載地址:點(diǎn)擊下載。

  后端處理代碼如下:

package com.test.web.test;import java.io.File;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.io.UnsupportedEncodingException;import java.util.Calendar;import java.util.Date;import javax.servlet.http.HttpServletRequest;import org.apache.commons.io.IOUtils;import org.springframework.context.annotation.Scope;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.ResponseBody;import org.springframework.web.multipart.MultipartFile;import org.springframework.web.multipart.MultipartHttpServletRequest;@Controller@Scope("prototype")@RequestMapping("/control/file")public class FileUpload {    @RequestMapping(value = "upload", method = RequestMethod.POST)    @ResponseBody    public boolean test(HttpServletRequest request) throws UnsupportedEncodingException {        String path = request.getsession().getServletContext().getRealPath("");        Calendar calendar = Calendar.getInstance();        calendar.setTime(new Date());        request.setCharacterEncoding("UTF-8");        path = String.format("%s//%s//%s//%s//%s//%s", path, "file", "upload", calendar.get(calendar.YEAR),                calendar.get(calendar.MONTH), calendar.get(calendar.DAY_OF_MONTH));        File filepath = new File(path);        if (!filepath.exists()) {            filepath.mkdirs();        }        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;        // 獲得文件        MultipartFile multipartFile = multipartRequest.getFile("Filedata");//與前端設(shè)置的fileDataName屬性值一致        String filename = multipartFile.getOriginalFilename();// 文件名稱        OutputStream os = null;        InputStream is = null;        File uploadFile = null;        try {            is = multipartFile.getInputStream();            if (is != null) {                uploadFile = new File(filepath, System.currentTimeMillis() + filename.substring(filename.lastIndexOf(".") - 1));                os = new FileOutputStream(uploadFile);                IOUtils.copy(is, os);                os.flush();            }        } catch (IOException e) {            e.printStackTrace();            return false;        } finally {            IOUtils.closeQuietly(os);            IOUtils.closeQuietly(is);        }        return true;    }}

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 大同市| 九寨沟县| 江源县| 平江县| 岗巴县| 汉中市| 德兴市| 甘肃省| 巍山| 青岛市| 高雄县| 霍林郭勒市| 瑞丽市| 临漳县| 会泽县| 大悟县| 张北县| 四川省| 镇平县| 文水县| 宁国市| 临江市| 康定县| 榆社县| 凌云县| 阿克苏市| 西华县| 双峰县| 无为县| 全南县| 清流县| 吉林省| 库尔勒市| 波密县| 遂昌县| 腾冲县| 肥乡县| 武邑县| 泗阳县| 合阳县| 澄江县|