Go: A simple jquery plugin ajaxfileupload implementation Ajax upload file example

Source: Internet
Author: User

Page code:

<!--introduction of related JS files, relative paths--
<script type= "Text/javascript" src= "Js/jquery.js" ></script>
<script type= "Text/javascript" src= "js/Ajaxfileupload. js "></script>

<!--functions to perform the upload file operation--
<script type= "Text/javascript" >
functionAjaxfileupload(){
$.Ajaxfileupload(
{
URL: ' Update.do?method=uploader ',//link to server address
Secureuri:false,
Fileelementid: ' Housemaps ',//File selection Box id attribute
DataType: ' xml ',//The format returned by the server, can be JSON
Success:function (data, status)//equivalent to the use of a try statement block in Java
{
$ (' #result '). HTML (' Add success ');
},
Error:function (data, status, E)//equivalent to the use of Catch statement blocks in Java
{
$ (' #result '). HTML (' Add failed ');
}
}

);

}
</script>

<body>
<form method= "POST" action= "Update.do?method=uploader" enctype= "Multipart/form-data" >
<input type= "File" id= "Housemaps" name= "Housemaps"/>
<input type= "button" value= "Submit" onclick= "Ajaxfileupload() "/>
</form>
<div id= "Result" ></div>

</body>

Server code:

public class Updateaction extends Dispatchaction {

Public Actionforward Uploader (actionmapping mapping, Actionform form,
HttpServletRequest request, HttpServletResponse response) {
Upformform upformform = (upformform) Form;
Formfile ff = Upformform.gethousemaps ();
try {
InputStream is = Ff.getinputstream ();
File File = new file ("d:/" + ff.getfilename ()); Specify the path and file name of the files store
OutputStream OS = new FileOutputStream (file);

Byte[] B = new byte[1024];
int len = 0;
while (len = Is.read (b))! =-1) {
Os.write (b, 0, Len);
}
Os.close ();
Is.close ();
} catch (Exception e) {
E.printstacktrace ();

}

return null;
}
}

Go: A simple jquery plugin ajaxfileupload implementation Ajax upload file example

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.