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

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

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

编写监听器以及相关的类 字串6

不用自己写了,源码可以从 字串6

http://www.telio.be/blog/2006/01/06/ajax-upload-progress-monitor-for-commons-fileupload-example里面下载,

字串8

下载地址 字串2

http://www.telio.be/blog/wp-content/uploads/2006/01/ajax-upload-1.0.war 字串3

下载完之后,你需要解包,在命令行中:

字串5

jar xvf ajax-upload-1.0.war 字串6

源码就在\WEB-INF\src下面 字串7

将要用到的文件有resources文件夹下,\WEB-INF\下面的dwr.xml和lib下面的jar文件 字串4

上传页面 字串8

在上面解开的包里面有index.jsp这个是上传页面,upload.jsp负责上传,resources包里面包含了dwr与服务器通讯的javascript脚本,你需要把index.jsp的form中的action换成你的struts action即可,然后把form中的file名改成你actionform中的file属性名,把页面中剩余的file去掉

字串1

index.jsp上传页面示例代码: 字串8

<%@ page contentType="text/html; charset=gb2312" language="java" 字串8

import="java.util.*" errorPage=""%> 字串3

<% 字串5

String path=request.getContextPath();

字串6

%> 字串6

<html locale="true">

字串3

<head> 字串8

<SCRIPT language=javascript>

字串6

function check_file() {

字串6

var strFileName=document.forms(0).file;

字串2

if (strFileName.value==""){ 字串7

alert("请选择要上传的文件"); 字串2

return false;

字串4

}

字串8

startProgress();

字串7

}

字串1

function loadmessage(){

字串5

<% 字串4

if (request.getAttribute("message") != null) { 字串9

%> 字串1

window.alert("<%=request.getAttribute("message")%>"); 字串3

window.returnValue="yes";

字串8

<%}%>

字串2

}

字串3

</SCRIPT> 字串4

<title>上传</title> 字串9

<script src='<%=path%>/resources/js/upload.js'> </script>

字串4

<script src='<%=path%>/dwr/interface/UploadMonitor.js'> </script>

字串1

<script src='<%=path%>/dwr/engine.js'> </script> 字串5

<script src='<%=path%>/dwr/util.js'> </script> 字串1

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="loadmessage()"> 字串3

<form name="form" method="post" action="<%=path%>/upload.do?method=upload" enctype="multipart/form-data" onSubmit="return check_file()"> 字串7

<table width="60%" border="0" cellspacing="1"> 字串4

<tr background-color=" #E7F5FE">

字串1

<td width="30%" align="right">从文件导入:</td> 字串2

<td width="51%"><input type="file" name="file" class="input"></td> 字串1

<td width="27%"><input type="submit" name="files" class="button_4"

字串7

style="border-style:None;width:71px;" value="确定" id="uploadbutton"> 字串2

</td> 字串4

</tr>

字串7

<tr align="left" background-color=" #E7F5FE">

字串4

<td colspan="3"> 字串6

<div id="progressBar" style="display: none;">

字串3

字串6

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