ITeye博客

jquery.uploadify 上传进度条

zcb11051 · 2011-01-06 15:41 · 编程语言 · Java · Struts · UP · MySQL · jQuery · Markdown

[code="Jsp"]<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 上传 | 清除队列 [/code] [code="java"]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(); } } }[/code] [code="xml"] /upload.jsp [/code] [code="xml"] com.mysql.jdbc.Driver jdbc:mysql://localhost:3306/nydot root 123 org.hibernate.dialect.MySQLDialect true true UTF-8 30 com/zcb/model/User.hbm.xml [/code]

评论(1)

  1. #1 楼 · bianhaihai · 2012-03-23 13:56

    :?

    <>

评论功能维护中,当前仅展示历史评论。