Adopt Dwr+ajax and Struts Development File Upload progress bar
writing a listener and related classes
Do not write yourself, the source code can be from
Http://www.telio.be/blog/2006/01/06/ajax-upload-progress-monitor-for-commons-fileupload-example inside Download,
Download Address
Http://www.telio.be/blog/wp-content/uploads/2006/01/ajax-upload-1.0.war
After downloading, you need to unpack the package at the command line:
Jar XVF Ajax-upload-1.0.war
The source is under/WEB-INF/SRC.
The files that will be used have the resources folder under/web-inf/, and the jar files under Dwr.xml and Lib below
upload page
There are index.jsp in the package above, this is the upload page, upload.jsp is responsible for uploading, the resources package contains the DWR and server communication JavaScript script, you need to replace the action in index.jsp form with your struts Action, and then change the file name in form to the file attribute name in your actionform, and remove the remaining file from the page.
index.jsp upload page Sample code:
<%@ page contenttype= "text/html; charset=gb2312 "Language=" Java "
Import= "java.util.*" errorpage= ""%>
<%
String Path=request.getcontextpath ();
%>
<script language=javascript>
function Check_file () {
var strfilename=document.forms (0). file;
if (strfilename.value== "") {
Alert ("Please select the file to upload");
return false;
}
Startprogress ();
}
function Loadmessage () {
<%
if (Request.getattribute ("message")!= null) {
%>
Window.alert ("<%=request.getattribute" ("message")%> ");
Window.returnvalue= "yes";
<%}%>
}
</SCRIPT>
<title> Upload