SmartUpload中文乱码的解决办法

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

SmartUpload中文乱码的解决办法:-修改源码:采用jspsmartupload上传文件时,如果文件名含有中文,在服务器端取得文件名是会出现乱码。如果表单项中填写了中文,一样会有乱码问题。看了下jspsmartupload的源码,改了两个地方,现在可以没有乱码问题了。第一个地方,修改类SmartUpload中的upload()方法Java代码publicvoidupload()throwsSmartUploadException,IOException,ServletException{inttotalRead=0;intreadBytes=0;longtotalFileSize=0L;booleanfound=false;StringdataHeader=newString();StringfieldName=newString();StringfileName=newString();StringfileExt=newString();StringfilePathName=newString();StringcontentType=newString();StringcontentDisp=newString();StringtypeMIME=newString();StringsubTypeMIME=newString();booleanisFile=false;m_totalBytes=m_request.getContentLength();m_binArray=newbyte[m_totalBytes];for(;totalReadm_totalBytes;totalRead+=readBytes)try{m_request.getInputStream();readBytes=m_request.getInputStream().read(m_binArray,totalRead,m_totalBytes-totalRead);}catch(Exceptione){thrownewSmartUploadException(Unabletoupload.);}for(;!found&&m_currentIndexm_totalBytes;m_currentIndex++)if(m_binArray[m_currentIndex]==13)found=true;elsem_boundary=m_boundary+(char)m_binArray[m_currentIndex];if(m_currentIndex==1)return;m_currentIndex++;do{if(m_currentIndex=m_totalBytes)break;dataHeader=getDataHeader();m_currentIndex=m_currentIndex+2;isFile=dataHeader.indexOf(filename)0;fieldName=getDataFieldValue(dataHeader,name);if(isFile){filePathName=getDataFieldValue(dataHeader,filename);fileName=getFileName(filePathName);fileExt=getFileExt(fileName);contentType=getContentType(dataHeader);contentDisp=getContentDisp(dataHeader);typeMIME=getTypeMIME(contentType);subTypeMIME=getSubTypeMIME(contentType);}getDataSection();if(isFile&&fileName.length()0){if(m_deniedFilesList.contains(fileExt))thrownewSecurityException(Theextensionofthefileisdeniedtobeuploaded(1015).);if(!m_allowedFilesList.isEmpty()&&!m_allowedFilesList.contains(fileExt))thrownewSecurityException(Theextensionofthefileisnotallowedtobeuploaded(1010).);if(m_maxFileSize(long)0&&(long)((m_endData-m_startData)+1)m_maxFileSize)thrownewSecurityException(String.valueOf((newStringBuffer(Sizeexceededforthisfile:)).append(fileName).append((1105).)));totalFileSize+=(m_endData-m_startData)+1;if(m_totalMaxFileSize(long)0&&totalFileSizem_totalMaxFileSize)thrownewSecurityException(TotalFileSizeexceeded(1110).);}if(isFile){com.jspsmart.upload.FilenewFile=newcom.jspsmart.upload.File();newFile.setParent(this);newFile.setFieldName(fieldName);newFile.setFileName(fileName);newFile.setFileExt(fileExt);newFile.setFilePathName(filePathName);newFile.setIsMissing(filePathName.length()==0);newFile.setContentType(contentType);newFile.setContentDisp(contentDisp);newFile.setTypeMIME(typeMIME);newFile.setSubTypeMIME(subTypeMIME);if(contentType.indexOf(application/x-macbinary)0)m_startData=m_startData+128;newFile.setSize((m_endData-m_startData)+1);newFile.setStartData(m_startData);newFile.setEndData(m_endData);m_files.addFile(newFile);}else{/***原来的代码*Stringvalue=newString(m_binArray,m_startData,(m_endData-m_startData)+1);*//***2009-9-17修改,解决取得request的参数的中文编码问题*/Stringvalue=newString(m_binArray,m_startData,(m_endData-m_startData)+1,utf-8);m_formRequest.putParameter(fieldName,value);}if((char)m_binArray[m_currentIndex+1]=='-')break;m_currentIndex=m_currentIndex+2;}while(true);}publicvoidupload()throwsSmartUploadException,IOException,ServletException{inttotalRead=0;intreadBytes=0;longtotalFileSize=0L;booleanfound=false;StringdataHeader=newString();StringfieldName=newString();StringfileName=newString();StringfileExt=newString();StringfilePathName=newString();StringcontentType=newString();StringcontentDisp=newString();StringtypeMIME=newString();StringsubTypeMIME=newString();booleanisFile=false;m_totalBytes=m_request.getContentLength();m_binArray=newbyte[m_totalBytes];for(;totalReadm_totalBytes;totalRead+=readBytes)try{m_request.getInputStream();readBytes=m_request.getInputStream().read(m_binArray,totalRead,m_totalBytes-totalRead);}catch(Exceptione){thrownewSmartUploadException(Unabletoupload.);}for(;!found&&m_currentIndexm_totalBytes;m_currentIndex++)if(m_binArray[m_currentIndex]==13)found=true;elsem_boundary=m_boundary+(char)m_binArray[m_currentIndex];if(m_currentIndex==1)return;m_currentIndex++;do{if(m_currentIndex=m_totalBytes)break;dataHeader=getDataHeader();m_currentIndex=m_currentIndex+2;isFile=dataHeader.indexOf(filename)0;fieldName=getDataFieldValue(dataHeader,name);if(isFile){filePathName=getDataFieldValue(dataHeader,filename);fileName=getFileName(filePathName);fileExt=getFileExt(fileName);contentType=getContentType(dataHeader);contentDisp=getContentDisp(dataHeader);typeMIME=getTypeMIME(contentType);subTypeMIME=getSubTypeMIME(contentType);}getDataSection();if(isFile&&fileName.length()0){if(m_deniedFilesList.contains(fileExt))thrownewSecurityException(Theextensionofthefileisdeniedtobeuploaded(1015).);if(!m_allowedFilesList.isEmpty()&&!m_allowedFilesList.contains(fileExt))thrownewSecurityException(Theextensionofthefileisnotallowedtobeuploaded(1010).);if(m_maxFileSize(long)0&&(long)((m_endData-m_startData)+1)m_maxFileS

1 / 11
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功