Huploadify V2.1+ SpringMVC上传文件的实现
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>学生成绩信息</title>
<link rel="stylesheet" type="text/css"
href="<%=basePath%>jquery/Huploadify-V2.1.2/Huploadify.css">
<script type="text/javascript"
src="<%=basePath%>jquery/Huploadify-V2.1.2/jquery.js"></script>
<script type="text/javascript"
src="<%=basePath%>jquery/Huploadify-V2.1.2/jquery.Huploadify.js"></script>
</head>
<script type="text/javascript">
$(function(){
var up = $('#upload').Huploadify({
auto:false,
fileTypeExts:'*.jpg;*.png;*.exe;*.mp3;*.mp4;*.zip;*.doc;*.docx;*.ppt;*.pptx;*.xls;*.xlsx;*.pdf',
multi:true,
fileSizeLimit:99999999,
breakPoints:true,
saveInfoLocal:true,
showUploadedPercent:true,//是否实时显示上传的百分比,如20%
showUploadedSize:true,
removeTimeout:9999999,
uploader:'<%=basePath%>'+ 'fileUpload',
onUploadStart:function(){
//up.settings('formData', {aaaaa:'1111111',bb:'2222'});
up.Huploadify('settings','formData', {aaaaa:'1111111',bb:'2222'});
},
onUploadSuccess:function(file){
//alert('上传成功');
},
onUploadComplete:function(){
//alert('上传完成');
},
/*getUploadedSize:function(file){
var data = {
data : {
fileName : file.name,
lastModifiedDate : file.lastModifiedDate.getTime()
}
};
var url = 'http://localhost/uploadfile/';
var uploadedSize = 0;
$.ajax({
url : url,
data : data,
async : false,
type : 'POST',
success : function(returnData){
returnData = JSON.parse(returnData);
uploadedSize = returnData.uploadedSize;
}
});
return uploadedSize;
} */
});
$('#btn1').click(function(){
up.stop();
});
$('#btn2').click(function(){
up.upload('*');
});
$('#btn3').click(function(){
up.cancel('*');
});
$('#btn4').click(function(){
up.disable();
});
$('#btn5').click(function(){
up.ennable();
});
});
</script>
<body>
<div id="upload"></div>
<button id="btn1">stop</button>
<button id="btn2">upload</button>
<button id="btn3">cancel</button>
<button id="btn4">disable</button>
<button id="btn5">ennable</button>
</body>
</html>
/**
* 查询学生信息列表
*
* @param name
* @return
* @throws NamingException
* @throws SQLException
*/
@ResponseBody
@RequestMapping(value = "/fileUpload", method = RequestMethod.POST)
public String fileUpload(@RequestParam Map<String, Object> map, HttpServletRequest request,
HttpServletResponse response, @RequestParam(value = "file", required = false) MultipartFile file) {
try {
String fileName = request.getParameter("fileName");
byte[] bytes = file.getBytes();
System.out.println(file.getOriginalFilename());
String uploadDir = request.getRealPath("/") + "upload";
File dirPath = new File(uploadDir);
if (!dirPath.exists()) {
dirPath.mkdirs();
}
String sep = System.getProperty("file.separator");
File uploadedFile = new File(uploadDir + sep + fileName);
FileCopyUtils.copy(bytes, uploadedFile);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
return "ok";
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/p"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver"
p:defaultEncoding="UTF-8" />
</beans>
Huploadify V2.1+ SpringMVC上传文件的实现的更多相关文章
- 2. SpringMVC 上传文件操作
1.创建java web项目:SpringMVCUploadDownFile 2.在项目的WebRoot下的WEB-INF的lib包下添加如下jar文件 com.springsource.com.mc ...
- springmvc上传文件,抄别人的
SpringMVC中的文件上传 分类: SpringMVC 2012-05-17 12:55 26426人阅读 评论(13) 收藏 举报 stringuserinputclassencoding 这是 ...
- 使用springMVC上传文件
control层实现功能: @RequestMapping(value="upload2") public String upLoad2(HttpServletRequest re ...
- SpringMVC上传文件(图片)并保存到本地
SpringMVC上传文件(图片)并保存到本地 小记一波~ 基本的MVC配置就不展示了,这里给出核心代码 在spring-mvc的配置文件中写入如下配置 <bean id="multi ...
- SpringMVC上传文件总结
如果是maven项目 需要在pom.xml文件里面引入下面两个jar包 <dependency> <groupId>commons-fileupload</groupId ...
- SpringMVC 上传文件 MultipartFile 转为 File
在使用 SpringMVC 上传文件时,接收到的文件格式为 MultipartFile,但是在很多场景下使用都需要File格式的文件,记录下以便日后使用. 以下mFile为MultipartFile文 ...
- springmvc 上传文件时的错误
使用springmvc上传文件一直失败,文件参数一直为null, 原来是配置文件没写成功. <bean id="multipartResolver" class=" ...
- SpringMVC上传文件的三种方式(转)
直接上代码吧,大伙一看便知 这时:commonsmultipartresolver 的源码,可以研究一下 http://www.verysource.com/code/2337329_1/common ...
- SpringMVC上传文件的三种方式
直接上代码吧,大伙一看便知 这时:commonsmultipartresolver 的源码,可以研究一下 http://www.verysource.com/code/2337329_1/common ...
随机推荐
- Available to Promise (ATP) in SAP-SD
One short note before we start off the subject: Availability refers to the projections of future mat ...
- html垂直居中
参考于http://www.cnblogs.com/yugege/p/5246652.html <!DOCTYPE html> <html lang="en"&g ...
- CSS盒模型详解(图文教程)
本文最初发表于博客园,并在GitHub上持续更新.以下是正文. 盒子模型 前言 盒子模型,英文即box model.无论是div.span.还是a都是盒子. 但是,图片.表单元素一律看作是文本,它们并 ...
- SQLSERVER群集故障转移笔记
SQLSERVER群集故障转移笔记 出自<SQLSERVER2012实施与管理实战指南> SQLSERVER故障转移 P41 事实上,从sqlserver2000到sqlserver200 ...
- 【MySQL运维实践】
什么是日志 日志(log)是一种顺序记录事件流水的文件 记录计算机程序运行过程中发生了什么 多种多样的用途 帮助分析程序问题 分析服务请求的特征.流量等 判断工作是否成功执行 等等…… MySQL日 ...
- 【Linq】常用语法汇总
语言继承查询(Language Integrated Query, LINQ),在C#编程语言中集成了查询语法,可以用相同的语法访问不同的数据源,LINQ提供了不同数据源的抽象层,所以可以使用相同语法 ...
- 深入浅出SharePoint——Search疑难排除
通过Search log http://richardstk.com/2013/12/23/using-the-sharepoint-2013-search-query-tool-with-searc ...
- 处理AsyncTask的内存泄漏问题
强引用AsyncTask导致了内存泄漏如下图 1.原因:activity销毁之后,AsyncTask线程可能依旧在执行,导致内存泄漏. 2.解决方法:查了一下大概有两个,一个是将函数声明为static ...
- [Python]运算符的优先级顺序
运算符 描述 ** 指数 (最高优先级) ~ + - 按位翻转, 一元加号和减号 (最后两个的方法名为 +@ 和 -@) * / % // 乘,除,取模和取整除 + - 加法减法 >> & ...
- 8.2Solr API使用(Facet查询)
转载请出自出处:http://eksliang.iteye.com/blog/2165882 一)概述 Facet是solr的高级搜索功能之一,可以给用户提供更友好的搜索体验.在搜索关键字的同时,能够 ...