uploadify插件与ssh上传文件到数据库
2011-08-10 21:37
363 查看
jsp代码:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>jQuery EasyUI</title>
<link rel="stylesheet" type="text/css" href="js/ui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="js/ui/themes/icon.css">
<link href="uploadify/uploadify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="js/ui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="uploadify/swfobject.js"></script>
<script type="text/javascript" src="uploadify/jquery.uploadify.v2.1.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#fileupload').uploadify({
'uploader' : 'uploadify/uploadify.swf',
'script' : 'upload_file.action',
'cancelImg' : 'uploadify/cancel.png',
'auto' : false,
'multi' : true, //是否支持多文件上传
'buttonText' : 'brower', //按钮上的文字
//'simUploadLimit' : 3, //一次同步上传的文件数目
'sizeLimit' : 409600000, //设置单个文件大小限制
//'queueSizeLimit' : 2, //队列中同时存在的文件个数限制
'queueID' : 'fileQueue',
'fileDesc' : '*.jpg;*.jpeg;*.bmp;*.gif;*.png', //如果配置了以下的'fileExt'属性,那么这个属性是必须的
'fileExt' : '*.jpg;*.jpeg;*.bmp;*.gif;*.png',//允许的格式
'fileDataName' : 'fileupload',
'removeCompleted' : false,
'wmode' : 'transparent',
'buttonImg' :'uploadify/add.png',
//'rollover' : true//值为true和false,设置为true时当鼠标移到浏览按钮上时有反转效果。
//'width' :200 //设置浏览按钮的宽度 ,默认值:110。
//'height' : 30 //设置浏览按钮的高度 ,默认值:30。
onComplete: function (event, queueID, fileObj, response, data) {
$('<li></li>').appendTo('.files').text(response);
},
onError: function(event, queueID, fileObj) {
alert("文件:" + fileObj.name + "上传失败");
},
onCancel: function(event, queueID, fileObj){
alert("取消了" + fileObj.name);
}
});
});
</script>
</head>
<body style="margin-left: 0px; margin-top: 0px; margin-bottom: 0px;">
<table id="test_tables"></table>
<div id="add" icon="icon-add" title="添加" closed="true" style="padding:5px;width:500px;height:400px;">
<div id="fileQueue"></div>
<input type="file" name="fileupload" id="fileupload" />
<p>
<a href="javascript:$('#fileupload').uploadifyUpload()">上传</a>|
<a href="javascript:$('#fileupload').uploadifyClearQueue()">取消上传</a>
</p>
<s:form id="insert">
<table align="left">
<tr>
<td>
资料编号:
</td>
<td>
<s:select id="addzlbh" list="dmtzllist" listKey="zlbh" listValue="zlbh" ></s:select>
</td>
</tr>
</table>
</s:form>
</div>
</body>
</html>
action主要方法的代码:
@Action(value="upload_file",results={@Result(name="success",type="json")})
public String uploadFile() {
Scwj scwj = new Scwj();
try {
String extName = ""; //保存文件拓展名
String nowTimeStr = ""; //保存当前时间
//获取拓展名
if (fileuploadFileName.lastIndexOf(".") >= 0){
extName = fileuploadFileName.substring(fileuploadFileName.lastIndexOf("."));
System.err.println(extName);
}
SimpleDateFormat sDateFormat;
Random r = new Random();
sDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); //时间格式化的格式
nowTimeStr = sDateFormat.format(new Date()); //当前时间
System.out.println(nowTimeStr);
InputStream is = new FileInputStream(fileupload);
byte[] bt = InputStreamToByte(is);
scwj.setFilename(fileuploadFileName);
scwj.setFiles(bt);
this.baseservice.save(scwj);
} catch (Exception e) {
e.printStackTrace();
}
return SUCCESS;
}
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>jQuery EasyUI</title>
<link rel="stylesheet" type="text/css" href="js/ui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="js/ui/themes/icon.css">
<link href="uploadify/uploadify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="js/ui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="uploadify/swfobject.js"></script>
<script type="text/javascript" src="uploadify/jquery.uploadify.v2.1.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#fileupload').uploadify({
'uploader' : 'uploadify/uploadify.swf',
'script' : 'upload_file.action',
'cancelImg' : 'uploadify/cancel.png',
'auto' : false,
'multi' : true, //是否支持多文件上传
'buttonText' : 'brower', //按钮上的文字
//'simUploadLimit' : 3, //一次同步上传的文件数目
'sizeLimit' : 409600000, //设置单个文件大小限制
//'queueSizeLimit' : 2, //队列中同时存在的文件个数限制
'queueID' : 'fileQueue',
'fileDesc' : '*.jpg;*.jpeg;*.bmp;*.gif;*.png', //如果配置了以下的'fileExt'属性,那么这个属性是必须的
'fileExt' : '*.jpg;*.jpeg;*.bmp;*.gif;*.png',//允许的格式
'fileDataName' : 'fileupload',
'removeCompleted' : false,
'wmode' : 'transparent',
'buttonImg' :'uploadify/add.png',
//'rollover' : true//值为true和false,设置为true时当鼠标移到浏览按钮上时有反转效果。
//'width' :200 //设置浏览按钮的宽度 ,默认值:110。
//'height' : 30 //设置浏览按钮的高度 ,默认值:30。
onComplete: function (event, queueID, fileObj, response, data) {
$('<li></li>').appendTo('.files').text(response);
},
onError: function(event, queueID, fileObj) {
alert("文件:" + fileObj.name + "上传失败");
},
onCancel: function(event, queueID, fileObj){
alert("取消了" + fileObj.name);
}
});
});
</script>
</head>
<body style="margin-left: 0px; margin-top: 0px; margin-bottom: 0px;">
<table id="test_tables"></table>
<div id="add" icon="icon-add" title="添加" closed="true" style="padding:5px;width:500px;height:400px;">
<div id="fileQueue"></div>
<input type="file" name="fileupload" id="fileupload" />
<p>
<a href="javascript:$('#fileupload').uploadifyUpload()">上传</a>|
<a href="javascript:$('#fileupload').uploadifyClearQueue()">取消上传</a>
</p>
<s:form id="insert">
<table align="left">
<tr>
<td>
资料编号:
</td>
<td>
<s:select id="addzlbh" list="dmtzllist" listKey="zlbh" listValue="zlbh" ></s:select>
</td>
</tr>
</table>
</s:form>
</div>
</body>
</html>
action主要方法的代码:
@Action(value="upload_file",results={@Result(name="success",type="json")})
public String uploadFile() {
Scwj scwj = new Scwj();
try {
String extName = ""; //保存文件拓展名
String nowTimeStr = ""; //保存当前时间
//获取拓展名
if (fileuploadFileName.lastIndexOf(".") >= 0){
extName = fileuploadFileName.substring(fileuploadFileName.lastIndexOf("."));
System.err.println(extName);
}
SimpleDateFormat sDateFormat;
Random r = new Random();
sDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); //时间格式化的格式
nowTimeStr = sDateFormat.format(new Date()); //当前时间
System.out.println(nowTimeStr);
InputStream is = new FileInputStream(fileupload);
byte[] bt = InputStreamToByte(is);
scwj.setFilename(fileuploadFileName);
scwj.setFiles(bt);
this.baseservice.save(scwj);
} catch (Exception e) {
e.printStackTrace();
}
return SUCCESS;
}
相关文章推荐
- Jquery-uploadify多文件上传插件使用介绍
- (jsp+ssh)jquery-uploadify 的用法(jquery异步上传插件,支持多文...
- 7.27--SSH学习之SpringMVC,Ajax请求、拦截器、文件上传和MyBatis访问数据库基本操作
- 文件上传利器JQuery上传插件Uploadify
- uploadify插件实现文件多媒体文件上传(spring mvc)
- 大文件上传Jquery 插件Uploadify-v2.1.4使用图解
- 文件上传插件Uploadify在Struts2中的应用,完整详细实例!-克拉
- 用ssh,加插件ckeditor,完成文件图片上传
- Jquery上传插件Uploadify无刷新上传文件
- 关于多文件上传插件uploadify使用总结
- 强大的支持多文件上传的jQuery文件上传插件Uploadify
- JQuery多文件上传插件Uploadify在ASP.NET中的实现
- 使用jquery插件uploadify结合commons fileupload实现多文件上传
- jquery uploadify插件多文件上传
- 文件上传利器JQuery上传插件Uploadify
- 大文件上传Jquery 插件Uploadify-v2.1.4使用图解
- 大文件上传Jquery 插件Uploadify-v2.1.4使用图解
- poi之Excel文件上传到数据库和导出(结合ssh)
- 大文件上传Jquery 插件Uploadify-v2.1.4使用图解
- 基于jQuery和Flash的多文件上传插件uploadify在asp.net下session丢失解决方案