Servlet 中 request.getInputStream()的流解析
我用一个AppCan做一个app,后台是java,现在手机端传输一个图片过来,据说是在request.getInputStream()可以获取,有兴趣可以看看我的手机端代码。现在问题是怎么取出流里面的数据?
程序代码:
<!DOCTYPE html> <html class="ui-mobile landscape min-width-240px min-width-320px min-width-480px min-width-768px min-width-1024px"> <head> <title> </title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"> <link rel="stylesheet" href="css/ui-media.css"> <link rel="stylesheet" href="css/ui-base.css"> <link rel="stylesheet" href="css/ui-apple.css"> <script src="js/zy_anim.js"> </script> <script src="js/zy_control.js"> </script> <script src="js/zy_tmpl.js"> </script> </head> <body class="ui-mobile-viewport" > <div id="page" class="ui-page ui-body-d ui-page-active ui-header-fixed" tabindex="0"> <div data-role="header" class="ui-header ui-bar-iphone " > <h1 class="ui-title" tabindex="0" role="heading" aria-level="1">Images</h1> <div class="ui-btn ui-btn-right ui-btn-corner-all ui-shadow ui-btn-a " onclick="actionsheet();"> <span class="ui-btn-inner ui-btn-corner-all"> <span class="ui-btn-text">选择</span> </span></div> </div> <div id="msgid" class="ui-bar ui-bar-e "> </div> <div class="ui-content ui-body-d"> <img id="imgid" src="img/2.png" style="height:500px;width:450px;position:absolute;left:0.5em;"/> </div> <div data-role="footer" class="ui-footer ui-bar-a ui-footer-fixed"> <div class="ui-bar ui-bar-a "> <div class="ui-btn ui-btn-corner-all ui-shadow ui-btn-a ui-btn-inline " onclick="viewpic();"> <span class="ui-btn-inner ui-btn-corner-all"> <span class="ui-btn-text">图片查看器</span> </span> <button class="ui-btn-hidden">按钮</button> </div> <div class="ui-btn ui-btn-corner-all ui-shadow ui-btn-a ui-btn-inline " onclick="downloadurl();"> <span class="ui-btn-inner ui-btn-corner-all"> <span class="ui-btn-text">下载网络图片</span> </span> <button class="ui-btn-hidden">按钮</button> </div> <div class="ui-btn ui-btn-corner-all ui-shadow ui-btn-a ui-btn-inline " onclick="uploadpic();"> <span class="ui-btn-inner ui-btn-corner-all"> <span class="ui-btn-text">上传</span> </span> <button class="ui-btn-hidden">按钮</button> </div> </div> </div> </div> <script> var imgurl = "wgt://img/2.png";//默认图片url //显示log function setLog(msg){ document.getElementById("msgid").innerHTML = msg; } //弹出actionSheet function actionsheet(){ uexWindow.actionSheet("选择图片", "取消", ["照相机拍摄","本地文件","网络文件"]); } //通过图片查看器查看图片 function viewpic(){ var ar = new Array(); ar[0]=imgurl; uexImageBrowser.open(ar); } //下载网络图片 var dopCode=1; var inSavePath=null; function downloadurl(){ if(imgurl.indexOf("http://")==0){ var q = imgurl.match(/.*\.(.*)/); inSavePath = (new Date()).getTime()+"."+q[1]; uexDownloaderMgr.createDownloader(dopCode); }else{ uexWindow.toast(0,5,"非网络图片",1000); } } //上传图片 var uploadHttp = "http://192.168.23.1:8888/fsjw/jubaoServlet"; var uopCode =2; function uploadpic(){ alert("upload"); if (imgurl.indexOf("http://") < 0) { alert(imgurl); alert(uploadHttp); uexUploaderMgr.createUploader(uopCode, uploadHttp); } else { uexWindow.toast(0, 5, "非本地图片", 1000); } } window.uexOnload = function(){ uexWindow.cbActionSheet = function(opId,dataType,data){ switch(parseInt(data)){ case 0: uexCamera.open(); break; case 1: uexFileMgr.explorer(""); break; case 2: uexWindow.prompt("提示", "输入网络图片URL", "",["确定","取消"]); break; } } uexWindow.cbPrompt=function(opId,dataType,data){ if(dataType==1){ var d = eval("("+data+")"); if(d.num=="0"){ if(d.value.indexOf('http://')>-1){ imgurl=d.value; document.getElementById("imgid").src=imgurl; } else alert("网络URL错误"); } } } uexCamera.cbOpen = function(opId,dataType,data){ if(dataType==0) { imgurl = data; document.getElementById("imgid").src=imgurl; } } uexFileMgr.cbExplorer = function(opId,dataType,data){ uexLog.sendLog(dataType); if(dataType==0){ uexLog.sendLog(data); imgurl = data; document.getElementById("imgid").src=imgurl; uexLog.sendLog(document.getElementById("imgid").src); } } //****************下载回调*************** uexDownloaderMgr.cbCreateDownloader=function(opId,dataType,data){ uexDownloaderMgr.download(dopCode,imgurl,inSavePath,0); setLog("开始下载图片"); } uexDownloaderMgr.onStatus = function(opId,fileSize,percent,status){ if(status == 0) setLog("下载进度:"+percent+"%"); if(status == 1){ setLog("下载完成"); imgurl = inSavePath; uexDownloaderMgr.closeDownloader(dopCode); } if(status == 2){ setLog("下载出错"); uexDownloaderMgr.closeDownloader(dopCode); uexFileMgr.deleteFileByPath(inSavePath); } } //****************************************** //****************上传回调*************** uexUploaderMgr.cbCreateUploader = function(opId,dataType,data){ uexUploaderMgr.uploadFile(uopCode,imgurl,"filename",1); setLog("开始上传图片"); } uexUploaderMgr.onStatus = function(opId,fileSize,percent,serverPath,status){ if(status==0) setLog("上传进度:"+percent+"%"); if(status == 1){ setLog("上传完成"); uexUploaderMgr.closeUploader(uopCode); } if(status == 2){ setLog("上传出错"); } } //****************************************** } </script> </body> </html>