秦皇岛网站关键词推广,海网站建设,wordpress 模板 中文乱码,微擎 网站开发工具上传文件的分类:无论什么方式上传文件,都要用post提交方式一:前端:表单方式上传文件后端:使用上传技术是apache中的Commons-fileupload.jarcommons-io.jarservlet:1.在表单提交的时候把表单中的所有的数据封装给request对象2.通过commons-fileupload的api方法转换request对象中…上传文件的分类:无论什么方式上传文件,都要用post提交方式一:前端:表单方式上传文件后端:使用上传技术是apache中的Commons-fileupload.jarcommons-io.jarservlet:1.在表单提交的时候把表单中的所有的数据封装给request对象2.通过commons-fileupload的api方法转换request对象中的数据到一个List集合中// Parse the requestList items upload.parseRequest(request);3.遍历 list集合,集合中都包含表单中所有的数据包含文件域和非文件域// Process the uploaded itemsIterator iter items.iterator();while (iter.hasNext()) {FileItem item iter.next();if (item.isFormField()) {//是非文件域String name item.getFieldName();String value item.getString();...} else {//文件域String fieldName item.getFieldName();String fileName item.getName();String contentType item.getContentType();boolean isInMemory item.isInMemory();long sizeInBytes item.getSize();...//真正上传文件item.write(服务端的某个目录)}}spring mvc:在springmvc中底层使用还是commons-fileupload.jar和commons-io.jar,说明spring mvc对apache的Commons-fileupload产品做二次封装,封装成:org.springframework.web.multipart.commons.CommonsMultipartResolver在springmvc上传文件api用CommonsMultipartResolver类中的apiclassorg.springframework.web.multipart.commons.CommonsMultipartResolver用springmvc的api上传文件MultipartFile的对象调用一个上传方法对象.transto();把文件上传到指定的服务器上方式二:前端:没有表单,用ajax上传文件,必须借助第三方js工具ajaxfileupload.js,类似的上传文件的js工具有很多,ajaxfileupload.js工具是基于jquery库//异步提交$.ajaxFileUpload({url:basePathuser/new,//提交的服务器地址secureuri:false,//url链接是否安全fileElementId:addHeadPicture,//文件域的idtype:post,//必须是post提交data:{loginName:loginName,password:password1,nickName:nickName,age:age,sex:sex,roleId:roleId},//传递的数据dataType:text,//注意text,可以写成jsonsuccess:function(data,status){//alert(data);//回的结果串中有其他的字符串,通过下面的方式//把没用的字符串替换掉datadata.replace(//g,);datadata.replace(,);datadata.replace(,);datadata.replace(//g,);datadata.replace(,);datadata.replace(,);alert(data);},error:function(){alert(请求失败!);}});后端:使用上传技术是apache中的Commons-fileupload.jarcommons-io.jarservlet:1.在表单提交的时候把表单中的所有的数据封装给request对象2.通过commons-fileupload的api方法转换request对象中的数据到一个List集合中// Parse the requestList items upload.parseRequest(request);3.遍历 list集合,集合中都包含表单中所有的数据包含文件域和非文件域// Process the uploaded itemsIterator iter items.iterator();while (iter.hasNext()) {FileItem item iter.next();if (item.isFormField()) {//是非文件域String name item.getFieldName();String value item.getString();...} else {//文件域String fieldName item.getFieldName();String fileName item.getName();String contentType item.getContentType();boolean isInMemory item.isInMemory();long sizeInBytes item.getSize();...//真正上传文件item.write(服务端的某个目录)}}spring mvc:在springmvc中底层使用还是commons-fileupload.jar和commons-io.jar,说明spring mvc对apache的Commons-fileupload产品做二次封装,封装成:org.springframework.web.multipart.commons.CommonsMultipartResolver在springmvc上传文件api用CommonsMultipartResolver类中的apiclassorg.springframework.web.multipart.commons.CommonsMultipartResolver用springmvc的api上传文件MultipartFile的对象调用一个上传方法对象.transferTo();把文件上传到指定的服务器上补充:能够给服务端提交数据的方式1.用form表单2.用超链接3.用ajax异步提交