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

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);
}
}

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

spring mvc 中Uploadify插件的使用的更多相关文章

  1. Spring 注解驱动(二)Servlet 3.0 注解驱动在 Spring MVC 中的应用

    Spring 注解驱动(二)Servlet 3.0 注解驱动在 Spring MVC 中的应用 Spring 系列目录(https://www.cnblogs.com/binarylei/p/1019 ...

  2. Spring mvc中@RequestMapping 6个基本用法

    Spring mvc中@RequestMapping 6个基本用法 spring mvc中的@RequestMapping的用法.  1)最基本的,方法级别上应用,例如: Java代码 @Reques ...

  3. spring mvc中使用freemark的一点心得

    参考文档: FreeMarker标签与使用 连接http://blog.csdn.net/nengyu/article/details/6829244 freemarker学习笔记--指令参考: ht ...

  4. Http请求中Content-Type讲解以及在Spring MVC中的应用

    引言: 在Http请求中,我们每天都在使用Content-type来指定不同格式的请求信息,但是却很少有人去全面了解content-type中允许的值有多少,这里将讲解Content-Type的可用值 ...

  5. Spring mvc中@RequestMapping 6个基本用法小结(转载)

    小结下spring mvc中的@RequestMapping的用法. 1)最基本的,方法级别上应用,例如: @RequestMapping(value="/departments" ...

  6. Spring MVC中处理静态资源的多种方法

    处理静态资源,我想这可能是框架搭建完成之后Web开发的”头等大事“了. 因为一个网站的显示肯定会依赖各种资源:脚本.图片等,那么问题来了,如何在页面中请求这些静态资源呢? 还记得Spring MVC中 ...

  7. Spring MVC 中的基于注解的 Controller【转】

    原文地址:http://my.oschina.net/abian/blog/128028 终于来到了基于注解的 Spring MVC 了.之前我们所讲到的 handler,需要根据 url 并通过 H ...

  8. spring mvc中的文件上传

    使用commons-fileupload上传文件所需要的架包有:commons-fileupload 和common-io两个架包支持,可以到Apache官网下砸. 在配置文件spring-mvc.x ...

  9. spring mvc中的valid

    当你希望在spring mvc中直接校验表单参数时,你可以采用如下操作: 声明Validator的方式: 1.为每一个Controller声明一个Validator @Controller publi ...

随机推荐

  1. c++打印蛇形矩阵

    一个m*n的矩阵里按照下图形式填充,最后形成的矩阵即为蛇形矩阵,下图是m=4, n =5时的蛇形矩阵: 方法一:逐层循环 #include <iostream> using namespa ...

  2. 解决长时间计划任务rsync同步进程数过多

      用rsync同步远程服务器,由于设置的的同步间隔较短(5分钟),这样一旦网速问题导致5分钟内同步不完.就会倒是同步紊乱,导致系统中很多rsync进程(# ps -aux | grep rsync) ...

  3. 详述Centos中的ftp命令的使用方法

    ftp服务器在网上较为常见,Linux ftp命令的功能是用命令的方式来控制在本地机和远程机之间传送文件,这里详细介绍Linux ftp命令的一些经常使用的命令,相信掌握了这些使用Linux 进行ft ...

  4. Maven的配置地址

    http://howtodoinjava.com/tools/eclipse/how-to-import-maven-remote-archetype-catalogs-in-eclipse/ htt ...

  5. JDK自带的定时任务

    import java.util.TimerTask; /** * 实现定时任务 * */ public class MyTimerTask extends TimerTask { @Override ...

  6. Unix下网络编程概述

    这部分我要学习的是Unix下的网络编程,参照的书籍是W. Richard. Stevens的<Unix网络编程>卷一和卷二,由于本身现在从事的工作是java后台开发,对客户端-服务器的这种 ...

  7. mysql 归档方案(一次性)

    一. 归档流程: 1. 导出需要的数据 2. 创建临时表table_tmp 3. 导入数据到临时表 4. 修改原始表名为table_bak 5. 修改临时表为原始表名 二.归档方式对比 1. sele ...

  8. 在Ubuntu下编译FFmpeg

    第一步:准备编译环境 .tar.bz2 -2245/ ./configure --enable-static--enable-shared--prefix=/usr/localmakesudomake ...

  9. memcache 的使用

    基础知识 memcached 是一个开源项目,旨在利用多个服务器内的多余 RAM 来充当一个可存放经常被访问信息的内存缓存.这里的关键是使用了术语缓存:memcached 为加载自他处的信息提供的是内 ...

  10. 通过Safari获取iOS设备的UUID,远程发送更是便捷

    1.获取UUID (1)在Safari上输入:http://fir.im/udid (2)点击安装描述文件,然后就可以获取到UUID了 2.fir.im提供一个非常好用的内侧平台 详情使用见:http ...