<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" /><meta http-equiv="x-ua-compatible" content="ie=7" />
<link href="../../css/example/css/default.css" rel="stylesheet" type="text/css" />
<link href="../../css/example/css/uploadify.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" language="javascript" src="../../script/jquery-1.3.2.min.js" charset="GBK"></script>
<script type="text/javascript" language="javascript" src="../../script/swfobject.js"></script>
<script type="text/javascript" language="javascript" src="../../script/jquery.uploadify.v2.1.4.js"></script>
<script type="text/javascript" language="javascript" src="../../script/jquery.uploadify.v2.1.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$("#uploadify").uploadify({
'uploader': '../../script/uploadify.swf',
'script': 'phT_test.do',
'cancelImg': '../../script/cancel.png',
'folder': 'photo',
'queueID': 'fileQueue',
'clieid':'clieid',
'auto': false,
'multi': true,
'fileExt':'*.jpg;*.jpeg;*.gif;*.png;*.bmp;',
'fileDesc':'选择*.jpg;*.jpeg;*.gif;*.png;*.bmp;',
'sizeLimit':'4000000',
'buttonText':'up',
'wmode':'transparent',
'removeCompleted' : false,
'fileDataName' : 'fileInput', //file的name,
'onSelect': function(e, queueId, fileObj){
alert("唯一标识:" + queueId + "\r\n" +
"文件名:" + fileObj.name + "\r\n" +
"文件大小:" + fileObj.size + "\r\n" +
"创建时间:" + fileObj.creationDate + "\r\n" +
"最后修改时间:" + fileObj.modificationDate + "\r\n" +
"文件类型:" + fileObj.type
);
},
'onComplete': function (event, queueID, fileObj, response, data) {
alert(fileObj.filePath);
$('#address').appendTo('.files').text(response);
},
'onError': function(event, queueID, fileObj) {
alert("文件:" + fileObj.name + "上传失败");
}
});
});
</script>
<script type="text/javascript">
$(function() {
$('#file_upload').uploadify({
'uploader': '../../script/uploadify.swf',
'script': 'phT_test.do', // 后台action 为 .do 请求
'cancelImg': '../../script/cancel.png',
'folder': 'photo',
'auto': false,
'multi': false,
'fileExt':'*.jpg;*.jpeg;*.gif;*.png;*.bmp;',
'fileDesc':'选择*.jpg;*.jpeg;*.gif;*.png;*.bmp;',
'sizeLimit':'4000000',
'buttonText':'File',
'wmode':'transparent',
'removeCompleted' : false,
'fileDataName' : 'fileInput', //file的name,
'onComplete': function (event, queueID, fileObj, response, data) {
$("#address").val(fileObj.filePath); // 这里是返回图片地址 的一个属性。保存到表中
},
'onError': function(event, queueID, fileObj) {
alert("文件:" + fileObj.name + "上传失败");
},
'onCancel': function(event, queueID, fileObj){
alert("取消" + fileObj.name);
}
});
});
</script>
<body>
<html>
单个文件上传
<div class="demo-box">
<input id="file_upload" type="file" name="fileInput" />
<p><a href="javascript:$('#file_upload').uploadifyUpload()">上传</a></p>
</div>
<input value="${address }" name="address" id="address" type="text"/>
多个文件上传
<div id="fileQueue" class="fileQueue"></div>
<input type="file" name="fileInput" id="uploadify" />
<p><a href="javascript:$('#uploadify').uploadifyUpload()">上传</a></p>
</body>
</html>
默认的CSS 文件加入 以下CSS样式(官网demo 中的基本样式)
#basic-demo .uploadifyQueueItem {
background-color: #F5F5F5;
border: 2px solid #E5E5E5;
font: 11px Verdana, Geneva, sans-serif;
margin-top: 5px;
padding: 10px;
width: 350px;
}
#basic-demo .uploadifyError {
background-color: #FDE5DD !important;
border: 2px solid #FBCBBC !important;
}
#basic-demo .uploadifyQueueItem .cancel {
float: right;
}
#basic-demo .uploadifyQueue .completed {
background-color: #E5E5E5;
}
#basic-demo .uploadifyProgress {
background-color: #E5E5E5;
margin-top: 10px;
width: 100%;
}
#basic-demo .uploadifyProgressBar {
background-color: #0099FF;
height: 3px;
width: 1px;
后台action
public class PhotoAction extends ActionBaseWach{
private File fileInput;
private String fileInputFileName;
private String fileInputContentType;
private String folder;
//set .get 略....
public String textajax(){
return "textajax";
}
public String test() {
ctx = ActionContext.getContext();
HttpServletResponse sd = ServletActionContext.getResponse();
sd.setContentType("GBK");
String path=ServletActionContext.getServletContext().getRealPath("/");
File fd=new File(path+folder); //floder就是js中配置的floder,这里要提供个String属性的floder,病get,set
if(!fd.exists()){
fd.mkdir();
}
try {
FileUtils.copyFile(fileInput, new File(fd ,fileInputFileName));
sd.getWriter().print(fileInputFileName+"上传成功");
} catch (IOException e) {
e.printStackTrace();
}
return null; //这里不需要页面转向,所以返回空就可以了
}
- 大小: 17 KB
分享到:
相关推荐
Uploadify + Struts2 实现文件上传详解 有需要的看看
uploadify+struts2多文件上传实例,解决了在firefox下的session问题,相信能帮助到你的
jquery上传插件uploadify+php完美实现强大的文件上传功能实例+程序_【PHP】.rar
uploadify+struts2+json 前台动态向后台传数据,并显示后台返回参数完成文件上传功能
代码使用Struts2框架和uploadify插架实现多文件上传功能。
完整的Uploadify+Struts2使用案例,前台用jQuery的DOM技术生成隐藏的input,后台由action负责上传,上传结束后提交前台的form。再由另外一个action完成链接和其他信息的持久化工作。
jquery+uploady+struts 实现图片上传
这是一个配置成功的例子,大家下载后可以自由扩展!
1 判断session是否失效 本实例没测试这个问题 但在工作项目中碰到了 但原因在这里记录下:web应用会存在一个session 而uploadify上传时也会产生一个新的session 导致在后台判断session是否失效时获取的session为null...
基于Uploadify+jsp文件上传刷新,直接运行该程序就可以 了
—》最近由于项目需要使用到一个上传插件,在网上发现uploadify挺不错,所以决定使用它,但是官网文档和例子是php的,而项目是SSI框架的,所以自己对uploadify在struts2中的使用进行了一番研究,最终实现了。...
jquery+uploadify+php脚本 批量上传文件demo脚本
struts2 +jquey uploadify3 2 实现多文件上传 可以运行的myeclipse工程 绝对好用 访问方式http: 127 0 0 1:8080 Struts2Uploadify upload jsp uploadify 使用说明: <a href "javascript:$ "#file ...
Jcrop+uploadify+php实现上传头像预览裁剪
Uploadify结合Struts2上传demo
jQuery Uploadify + Apache Fileupload异步上传文件示例
自己通过搜集网上各种资料整理的uploadify+jsp实现文件批量上传,总结了一些使用心得,内有uploadify的使用说明和自己实现的一个Demo,demo直接导入myeclipse即可运行。
uploadify 多文件上传插件 多浏览器兼容
使用jQuery的uploadify插件实现了与java结合的多文件上传功能,与commons-fileupload相结合,大大提高了上传速度
struts2 + uploadify上传文件示例