Tag - html5

jersey html5 文件上传 FormData restful    2017-07-12 16:08:46    812

本文主要使用jersey1.x,结合html5的FormData对象来进行多文件提交示例讲解

FormData

FormData对象是html5的一个对象,目前的一些主流的浏览器都已经兼容。IE8及以下是不支持FormData的。FormData还支持困扰众多开发者已久的ajax的上传文件,以前我们上传文件,需要写一个表单直接刷新提交,但是这里不需要了。

代码示例

html

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <script src="js/jquery.js" type="text/javascript"></script>
  6. <script type="text/javascript">
  7. function test(){
  8. var form = new FormData(document.getElementById("form1"));
  9. $.ajax({
  10. url:"http://192.168.2.8:8066/file/multiFiles/",
  11. type:"post",
  12. data:form,
  13. processData:false,
  14. contentType:false,
  15. success:function(data){
  16. alert("pass");
  17. },
  18. error:function(e){
  19. alert("错误!!");
  20. }
  21. });
  22. }
  23. </script>
  24. </head>
  25. <body>
  26. <form id