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>
<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插件的使用的更多相关文章
- Spring 注解驱动(二)Servlet 3.0 注解驱动在 Spring MVC 中的应用
Spring 注解驱动(二)Servlet 3.0 注解驱动在 Spring MVC 中的应用 Spring 系列目录(https://www.cnblogs.com/binarylei/p/1019 ...
- Spring mvc中@RequestMapping 6个基本用法
Spring mvc中@RequestMapping 6个基本用法 spring mvc中的@RequestMapping的用法. 1)最基本的,方法级别上应用,例如: Java代码 @Reques ...
- spring mvc中使用freemark的一点心得
参考文档: FreeMarker标签与使用 连接http://blog.csdn.net/nengyu/article/details/6829244 freemarker学习笔记--指令参考: ht ...
- Http请求中Content-Type讲解以及在Spring MVC中的应用
引言: 在Http请求中,我们每天都在使用Content-type来指定不同格式的请求信息,但是却很少有人去全面了解content-type中允许的值有多少,这里将讲解Content-Type的可用值 ...
- Spring mvc中@RequestMapping 6个基本用法小结(转载)
小结下spring mvc中的@RequestMapping的用法. 1)最基本的,方法级别上应用,例如: @RequestMapping(value="/departments" ...
- Spring MVC中处理静态资源的多种方法
处理静态资源,我想这可能是框架搭建完成之后Web开发的”头等大事“了. 因为一个网站的显示肯定会依赖各种资源:脚本.图片等,那么问题来了,如何在页面中请求这些静态资源呢? 还记得Spring MVC中 ...
- Spring MVC 中的基于注解的 Controller【转】
原文地址:http://my.oschina.net/abian/blog/128028 终于来到了基于注解的 Spring MVC 了.之前我们所讲到的 handler,需要根据 url 并通过 H ...
- spring mvc中的文件上传
使用commons-fileupload上传文件所需要的架包有:commons-fileupload 和common-io两个架包支持,可以到Apache官网下砸. 在配置文件spring-mvc.x ...
- spring mvc中的valid
当你希望在spring mvc中直接校验表单参数时,你可以采用如下操作: 声明Validator的方式: 1.为每一个Controller声明一个Validator @Controller publi ...
随机推荐
- STL学习笔记(序列式容器)
Vector Vector是一个动态数组. 1.Vector的操作函数 构造.拷贝和析构 vector<Elem> c //产生一个空vector ,其中没有任何元素 vector< ...
- windows 网站迁移到linux
从windows迁移网站到linux 发现乱码 出现这种情况的原因为两种操作系统的中文压缩方式不同,在windows环境中中文一般为gbk,而在linux环境中为utf8,这就导致了在windows下 ...
- 利用nginx搭建https服务器
一.HTTPS简介 HTTPS其实是有两部分组成:HTTP + SSL / TLS,也就是在HTTP上又加了一层处理加密信息的模块.服务端和客户端的信息传输都会通过TLS进行加密,所以传输的数据都是加 ...
- Fiddler 过滤器的使用
只显示制定HOST的SESSION
- vivado2013.4和modelsim联合仿真
vivado2013.4和modelsim联合仿真 Hello,Panda 最近在做Zynq的项目,曾经尝试使用ISE+PlanAhe ...
- python 迭代 及列表生成式
什么是迭代 在Python中,如果给定一个list或tuple,我们可以通过for循环来遍历这个list或tuple,这种遍历我们成为迭代(Iteration). 在Python中,迭代是通过 for ...
- ListView中CheckBox使用问题
因为CheckBox的点击事件优先级比ListView的高,所以当ListView中使用CheckBox会导致ListView的setOnItemClickListener失去响应. 解决的方法:在C ...
- 在Ubuntu下利用Eclipse开发FFmpeg配置小结
首先需要编译FFmpeg得到头文件和lib文件,参见:在Ubuntu下编译FFmpeg 选择File-New-C Project 选择Executable下的Empty Project,右侧选择Lin ...
- 传统数据仓库架构与Hadoop的区别
一, 下面一张图为传统架构和Hadoop的区别 主要讲以下横向扩展和扩展横向扩展:(Mpp 是hash分布,具有20节点)添加新的设备和现有的设备一起提供负载能力.Hadoop中系统扩容时,系统平台增 ...
- python 基础 9.9 查询数据
#/usr/bin/python #-*- coding:utf-8 -*- #@Time :2017/11/24 4:21 #@Auther :liuzhenchuan #@File : ...