1. Directly on the simplest one Ajax upload pictures asynchronously, and preview
Html:
Servlet:
protected void DoPost (HttpServletRequest request, httpservletresponse response)
throws Servletexception, IOException {
Diskfileitemfactory factory = new Diskfileitemfactory ();
Servletfileupload upload = new Servletfileupload (factory);
String path = Request.getservletcontext (). Getrealpath ("/upload");
String name = null;
try {
list<fileitem> items = upload.parserequest (request);
for (Fileitem item:items) {
if (Item.isformfield ()) {
System.out.println (item.getfieldname () + ":" + Item.getstring ());
} else {
name = Item.getname ();
Item.write (New File (Path,name));
}
PrintWriter out = Response.getwriter ();
Out.print ("{");
Out.print ("url:\" "+ name +" \ ");
Out.print ("}");
catch (Exception e) {
e.printstacktrace ();
}
}
2. There will be a ajaxupload.js, there are many online.
The above is a small series for everyone to bring the Ajax upload pictures and preview the full content of the simple implementation, I hope to help you, a lot of support cloud Habitat Community ~