jquery.uploadify 上传进度条

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/uploadify.css" />
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.uploadify.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#up').fileUpload ({
//以下参数均是可选
'uploader' : 'flash/uploader.swf', //指定上传控件的主体文件,默认‘uploader.swf’
'script' : 'uploadify.action', //指定服务器端上传处理文件,默认‘upload.php’
'cancelImg' : 'image/cancel.png', //指定取消上传的图片,默认‘cancel.png’
'fileDataName':'up',
'auto' : false, //选定文件后是否自动上传,默认false
'folder' : '/file', //要上传到的服务器路径,默认‘/’
'muti' : true, //是否允许同时上传多文件,默认false
'queueSizeLimit' : 2, //队列中同时存在的文件个数限制
//'fileDesc' : 'rar文件或zip文件', //出现在上传对话框中的文件类型描述
//'fileExt' : '*.rar;*.zip', //控制可上传文件的扩展名,启用本项时需同时声明fileDesc
'sizeLimit': 99999999999, //控制上传文件的大小,单位byte
'multi': true,//是否支持多文件上传
'buttonText': 'Browse Files',//按钮上的文字
'simUploadLimit' :5 //多文件上传时,同时上传文件数目限制
});
});
</script>

</head>

<body>
<input type="file" id="up" name="up" /><a href="javascript:$('#up').fileUploadStart()">上传</a>
| <a href="javascript:$('#up').fileUploadClearQueue();">清除队列</a>
</body>
</html>

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

public class UploadAction extends ActionSupport {

/**
*
*/
private static final long serialVersionUID = 2854105381965508552L;

private static final int BUFFER_SIZE = 20 * 1024; // 20K

private File up;

private String upFileName;



public File getUp() {
return up;
}


public void setUp(File up) {
this.up = up;
}


public String getUpFileName() {
return upFileName;
}


public void setUpFileName(String upFileName) {
this.upFileName = upFileName;
}


public String execute()
{
LOG.debug("fileName"+upFileName);
String newFileName = upFileName;//new Date().getTime() + getExtention(fileName);
File imageFile = new File(ServletActionContext.getServletContext()
.getRealPath("/file")
+ "/" + newFileName);

upload(up, imageFile);

return SUCCESS;
}



private static void upload(File src, File dst) {
try {
InputStream in = null;
OutputStream out = null;
try {
in = new BufferedInputStream(new FileInputStream(src),
BUFFER_SIZE);
out = new BufferedOutputStream(new FileOutputStream(dst),
BUFFER_SIZE);
byte[] buffer = new byte[BUFFER_SIZE];
while (in.read(buffer) > 0)
{
out.write(buffer);
}
}
finally
{
if (null != in)
{
in.close();
}
if (null != out)
{
out.close();
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}







}

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="struts2" extends="struts-default">
<action name="uploadify" class="upload">
<result name="success">
/upload.jsp
</result>
</action>
</package>
<constant name= "struts.multipart.maxSize" value="99999999999" />
</struts>

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/nydot</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>123</value>
</property>
</bean>

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="connection.useUnicode">true</prop>
<prop key="connection.characterEncoding">UTF-8</prop>
<prop key="hibernate.jdbc.batch_size">30</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/zcb/model/User.hbm.xml</value>
</list>
</property>
</bean>

<bean id="genericDao" class="com.zcb.dao.impl.UserDaoImpl">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>

<bean id="userDao" class="com.zcb.dao.impl.UserDaoImpl">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>

<bean id="findAll" class="com.zcb.action.UserAction" scope="prototype">
<property name="userDao" ref="userDao"></property>
</bean>

<bean id="upload" class="com.zcb.action.UploadAction" scope="prototype">
</bean>


</beans>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值