ajax实现文件异步上传并回显文件相关信息功能示例
程序员文章站
2022-05-14 22:31:33
本文实例讲述了ajax实现文件异步上传并回显文件相关信息功能。分享给大家供大家参考,具体如下:
上传文件的信息
本文实例讲述了ajax实现文件异步上传并回显文件相关信息功能。分享给大家供大家参考,具体如下:
上传文件的信息
<div class="form-group"> <div class="col-sm-4"> <label class="control-label">应用文件</label> </div> <div class="col-sm-8"> <input type="file" name="appfile" id="appfile"> <input type="submit" value="确认上传" id="subm"> </div>
ajax提交
$("#subm").click(function(){ var formdata = new formdata(); formdata.append("appfile", document.getelementbyid("appfile").files[0]); alert("8888888888888888888888888"); $.ajax({ url: '${ctx}/appresources/fileupload.shtml', type: "post", data: formdata, datatype: "json", contenttype: false, processdata: false, success: function (data) { alert("上传成功"); $("#versioncode").val(data.versioncode); $("#appversion").val(data.appversion); $("#apppackagename").val(data.apppackagename); }, error: function () { alert("上传失败!"); } }); });
后台处理:
@responsebody @requestmapping("fileupload") public jsonobject fileupload(multipartfile appfile,model model,httpservletrequest request,httpservletresponse response) { servletcontext //........................省略 string infos=apkutil.getapkinfo(needpath+"source"+file.separator+"apk"+file.separator+filename); string[] info=infos.split(","); string versioncode=info[0];//版本号 string versionname=info[1];//版本名 string packagename=info[2];//包名 string appname=filename; appresourcesformmap appresourcesformmap = getformmap(appresourcesformmap.class); appresourcesformmap.put("appname",filename); appresourcesformmap.put("appversion",versionname); appresourcesformmap.put("apppackagename",packagename); appresourcesformmap.put("versioncode", versioncode); system.out.println(appresourcesformmap); //model.addattribute("appresources", appresourcesformmap); jsonobject fromobject = jsonobject.fromobject(appresourcesformmap); //string string = fromobject.tostring(); return fromobject; }
上一篇: 广州酒家叉烧包要蒸多久?
下一篇: checkbox在vue中的用法小结