[Fine] Use Dwr+ajax and Struts development file upload progress bar

Source: Internet
Author: User
Tags file upload progress bar

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.