<%@ 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上传文件的实现的更多相关文章

  1. 2. SpringMVC 上传文件操作

    1.创建java web项目:SpringMVCUploadDownFile 2.在项目的WebRoot下的WEB-INF的lib包下添加如下jar文件 com.springsource.com.mc ...

  2. springmvc上传文件,抄别人的

    SpringMVC中的文件上传 分类: SpringMVC 2012-05-17 12:55 26426人阅读 评论(13) 收藏 举报 stringuserinputclassencoding 这是 ...

  3. 使用springMVC上传文件

    control层实现功能: @RequestMapping(value="upload2") public String upLoad2(HttpServletRequest re ...

  4. SpringMVC上传文件(图片)并保存到本地

    SpringMVC上传文件(图片)并保存到本地 小记一波~ 基本的MVC配置就不展示了,这里给出核心代码 在spring-mvc的配置文件中写入如下配置 <bean id="multi ...

  5. SpringMVC上传文件总结

    如果是maven项目 需要在pom.xml文件里面引入下面两个jar包 <dependency> <groupId>commons-fileupload</groupId ...

  6. SpringMVC 上传文件 MultipartFile 转为 File

    在使用 SpringMVC 上传文件时,接收到的文件格式为 MultipartFile,但是在很多场景下使用都需要File格式的文件,记录下以便日后使用. 以下mFile为MultipartFile文 ...

  7. springmvc 上传文件时的错误

    使用springmvc上传文件一直失败,文件参数一直为null, 原来是配置文件没写成功. <bean id="multipartResolver" class=" ...

  8. SpringMVC上传文件的三种方式(转)

    直接上代码吧,大伙一看便知 这时:commonsmultipartresolver 的源码,可以研究一下 http://www.verysource.com/code/2337329_1/common ...

  9. SpringMVC上传文件的三种方式

    直接上代码吧,大伙一看便知 这时:commonsmultipartresolver 的源码,可以研究一下 http://www.verysource.com/code/2337329_1/common ...

随机推荐

  1. 解读 --- 基于微软企业商务应用平台 (Microsoft Dynamics 365) 之上的人工智能 (AI) 解决方案

    9月25日微软今年一年一度的Ignite 2017在佛罗里达州奥兰多市还是如期开幕了.为啥这么说?因为9月初五级飓风厄玛(Hurricane Irma) 在佛罗里达州登陆,在当地造成了挺大的麻烦.在这 ...

  2. input radio单选框样式优化

    HTML代码: <form> <div> <input id="item1" type="radio" name="it ...

  3. 快速配置webpack 4.x

    区分开发模式和生产模式: npm run start——开发模式,启用devServer,文件的改动实时更新.刷新 npm run build——生产模式,打包文件到dist文件夹 // packag ...

  4. 简单的分页小demo

    public class Demo { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Sy ...

  5. javascript获取网页各种高宽及位置总结

    screen对象 获取屏幕的高宽(分辨率) screen.width //屏幕的宽 screen.height //屏幕的高 screen.availWidth //屏幕可用宽度 屏幕的像素高度减去系 ...

  6. 负载均衡(Load Balancing)学习笔记(一)

    概述 在分布式系统中,负载均衡(Load Balancing)是一种将任务分派到多个服务端进程的方法.例如,将一个HTTP请求派发到实际的Web服务器中执行的过程就涉及负载均衡的实现.一个HTTP请求 ...

  7. python编写脚本

    #!/usr/bin/env python #-*- coding:utf-8 -*- import sys import os from subprocess import Popen,PIPE c ...

  8. Azure 实例元数据服务

    Azure 实例元数据服务提供有关可用于管理和配置虚拟机的正在运行的虚拟机实例的信息. 这包括 SKU.网络配置和即将发生的维护事件等信息. 若要详细了解可用信息类型,请参阅元数据类别. Azure ...

  9. Huawei 常用基本配置命令一

    华为交换机的三种视图: 用户视图, 系统视图, 接口视图 用户视图: 刚开始登入交换机时的视图,一般看到的是尖括号<> . save // 配置完交换机后保存当前配置的命令 system- ...

  10. WinThruster清理电脑注册表

    电脑因为安装卸载各种软件,长时间工作,越来越卡慢,很大程度上和电脑中一些老旧不用的注册表有关,一些遗留问题也成为隐患. 今天我们主要来讲一下一些不用,没用的注册表清理问题. 无意间在网上看了一个软件, ...