|
用JSP分析multipart/form-data基于表单的文件上传(1) <% int iTotalByte,iTotalRead,iReadByte; iTotalByte=request.getContentLength(); iTotalRead=0; iReadByte=0; byte[] Buffer=new byte[iTotalByte]; if(iTotalByte>0) { for(;iTotalRead<iTotalByte;iTotalRead+=iReadByte) { try { iReadByte=request.getInputStream().read(Buffer,iTotalRead,iTotalByte-iTotalRead); } catch(Exception e) { e.printStackTrace(); } } String strContentType=request.getContentType(); //数据处理开始 String strBuffer=new String(Buffer); %><!--<br>表单数据:<br>strBuffer<br>--><% String strBoundary="--"+strContentType.substring(strContentType.lastIndexOf("=")+1,strContentType.length()); String strArray[]=strBuffer.split(strBoundary);
String strSubString; int iBegin,iEnd; iBegin=0;iEnd=0; String strFieldName=""; String strFieldValue=""; String strFilePath=""; String strFileName=""; String strFileType=""; boolean bTrue; bTrue=false; int iLocation=0; for(int iIndex=1;iIndex<strArray.length-1;iIndex++) { strSubString=strArray[iIndex]; iBegin=strSubString.indexOf("name=\"",0); if(iBegin!=-1) { strFieldName="";strFieldValue=""; strFilePath="";strFileName="";strFileType=""; iEnd=strSubString.indexOf("\"",iBegin+6); strFieldName=strSubString.substring(iBegin+6,iEnd); iBegin=strSubString.indexOf("filename=\"",0); if(iBegin!=-1)
|