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 ...
随机推荐
- js:获得时间
<script type="text/javascript"> function bodyLoad() { var dateTime = new Date(); var ...
- org.springframework.beans.factory.UnsatisfiedDependencyException
© 版权声明:本文为博主原创文章,转载请注明出处 1.问题描述: 搭建SSH框架,启动时报错如下: 严重: Context initialization failed org.springframew ...
- 使用wifi连接eclipse进行android程序调试
首先手机必须是root过的.能够使用百度一键root工具. 然后,在手机中打开这个终端(terminal)应用,输入例如以下命令: su setprop service ...
- Python内置函数之staticmethod()
staticmethod(function)返回函数的静态方法.一般来说,实例对象调用类方法不用传入参数,因为实例对象本身隐式的作为第一个参数传入了.而采用静态方法之后,实例对象在调用类方法时必须传入 ...
- spring 事件驱动模型简介
事件驱动模型简介 事件驱动模型也就是我们常说的观察者,或者发布-订阅模型:理解它的几个关键点: 首先是一种对象间的一对多的关系:最简单的如交通信号灯,信号灯是目标(一方),行人注视着信号灯(多方): ...
- AjaxPro.2.dll AjaxPro.AjaxMethod 前后台交互
我们需要下载 AjaxPro.2.zip.然后把下载到的 AjaxPro.2.dll 的文件引入到项目. 1.接着,在 Web.config 的 <system.web> 标签下写入以下内 ...
- java.io.IOException: Illegal partition for 67 (-1)
今天写MapReduce的分区进行排序的功能,自己写了一个Partitioner,然后用的时候就错了 public static class MyPartition extends Partition ...
- [C++]二维数组还是一维数组?
记得刚学习C++那会这个问题曾困扰过我,后来慢慢形成了不管什么时候都用一维数组的习惯,再后来知道了在一维数组中提出首列元素地址进行二维调用的办法.可从来没有细想过这个问题,最近自己写了点代码测试下,虽 ...
- .Net中多线程类的使用和总结
lock, Monitor, Thread, Join, BackGroundWorker. 消费者和生产者.Async 委托Invoke TypeHandle中BlockIndex. http: ...
- python基础: day4作业计算器
作业:计算器开发 实现加减乘除及拓号优先级解析 用户输入 1 - 2 * ( (60-30 +(-40/5) * (9-2*5/3 + 7 /3*99/4*2998 +10 * 568/14 )) - ...