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 ...
随机推荐
- 远程链接mysql数据库
mysql -P3306 -uroot -proot 显示最大连接数 show variables like '%max_connections%'; 设置最大链接数 ;//默认100--只对当前进程 ...
- 合并apk和odex
Android的ROM中有很多odex文件,相对于APK中的dex文件而言这个odex有什么作用呢? 如果你仔细观察会发现文件名时一一对应的,同时那些对应的apk文件中没有dex文件.这样做可以使其厂 ...
- Delphi 泛型(三十篇)
Delphi 泛型(三十篇)http://www.cnblogs.com/jxgxy/category/216671.html
- 走进windows编程的世界-----消息处理函数(3)
二 定时器消息 1 定时器消息 WM_TIMER 依照定时器设置时间段,自己主动向窗体发送一个定时器消息WM_TIMER. 优先级比較低. 定时器精度比較低,毫秒级别.消息产生时间也精度比較低 ...
- SpringBoot使用MyBatis报错:Error invoking SqlProvider method (tk.mybatis.mapper.provider.base.BaseInsertProvider.dynamicSQL)
© 版权声明:本文为博主原创文章,转载请注明出处 1. 错误描述 使用SpringBoot集成MyBatis框架,并且使用 mapper-spring-boot-starter 自动生成MyBati ...
- Linux基础ls命令
ls 命令是linux下最常用的命令,通过ls 命令不仅可以查看linux文件夹包含的文件而且可以查看文件权限(包括目录.文件夹.文件权限)查看目录信息等等.ls 命令在日常的linux操作中用的 ...
- HTML5 2D平台游戏开发#9蓄力技
在很多动作游戏中,玩家操控的角色可以施放出比普通攻击更强力的蓄力技,一般操作为按住攻击键一段时间然后松开,具体效果像下面这张图: 要实现这个操作首先要记录下按键被按住的时间,初始是0: this.sa ...
- python 迭代 及列表生成式
什么是迭代 在Python中,如果给定一个list或tuple,我们可以通过for循环来遍历这个list或tuple,这种遍历我们成为迭代(Iteration). 在Python中,迭代是通过 for ...
- CentOS: Make Command not Found and linux xinetd 服务不能启动
在centos 安装编译器 yum -y install gcc automake autoconf libtool make linux xinetd 服务不能启动: [root@capaa xin ...
- 走进科学之揭开神秘的"零拷贝"!
"零拷贝"这三个字,想必大家多多少少都有听过吧,这个技术在各种开源组件中都使用了,比如kafka,rocketmq,netty,nginx等等开源框架都在其中引用了这项技术 ...