RSS
热门关键字:  Linux  图形  项目管理  LAMP  java
当前位置 : 主页>开源技术>AJAX技术>列表

采用dwr ajax和struts开发文件上传进度条

来源:中国开源社区 作者:sherman 时间:2007-09-18 点击:

}

字串6

FileUploadForm fuf = (FileUploadForm) form; 字串4

FormFile file = fuf.getFile(); 字串3

try {

字串7

if (file == null) { 字串7

log.info(">>>>>>>>>>>>>>>file为空");

字串8

return mapping.findForward("success");

字串9

} 字串5

} catch (Exception e) { 字串8

e.printStackTrace();

字串5

} 字串9

String fname = file.getFileName();

字串6

int t = 0;

字串8

for (int i = 0; i < fname.length(); i ) {

字串5

if (fname.charAt(i) == '.') {

字串7

t = i; 字串7

} 字串9

}

字串2

String filename = null; 字串8

if (t > 0) {

字串6

filename = fname.substring(0, t); 字串4

}

字串1

log.info(">>>>>>>>>>>>>>>文件名:" filename);

字串4

String filepath = path "dataimport/upfiles/" fname; 字串5

File f = new File(path "dataimport/upfiles/");

字串3

log.info(">>>>>>>>>>>>>>>文件生成路径:" filepath); 字串5

if (!f.exists()) {

字串1

f.mkdirs(); 字串1

} else { 字串6

log.info(">>>>>>>>>>>>>>>路径存在"); 字串1

}

字串2

InputStream stream = file.getInputStream(); 字串8

OutputStream os = new FileOutputStream(path "dataimport/upfiles/"

字串7

fname); 字串4

int readBytes = 0;

字串2

byte buffer[] = new byte[8192]; 字串4

while ((readBytes = stream.read(buffer, 0, 8192)) != -1) {

字串3

os.write(buffer, 0, readBytes);

字串8

} 字串2

os.close();

字串2

stream.close();

字串6

file.destroy(); 字串7

字串4

String message = "成功!";

字串7

request.setAttribute("message", message); 字串7

return mapping.findForward("success"); 字串1

} 字串8

最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册