byte[] Buffer=new byte[4096];
InputStream InData=null;
OutputStream outData=null;
int iSize; if(odbcRs.next())
{
outData=response.getOutputStream();
InData=odbcRs.getBinaryStream("BLOB字段");
response.setContentType("image/*");
while(true)
{
iSize=InData.read(Buffer);
if(iSize==-1)
{
break;
}
outData.write(Buffer,0,iSize);
}
outData.flush();
response.flushBuffer();
}

解决方案 »

  1.   

    是否是你的上载拆分出现了问题.
    InputStream InData=null;
    int iSize,iLength;
    iLength=request.getContentLength();
    byte[] Buffer=new byte[iLength];
    byte[] Byte_File;
    if(iLength>0)
    {
    InData=request.getInputStream();
    String ContentType=request.getContentType();
    iSize=InData.read(Buffer);
    if(iSize!=-1)
    {
    //数据处理开始
    String FileData=new String(Buffer);
    //正则字串:"name=\"";
    //正则字串:"filename=\"";

    String strSplit=ContentType.substring(ContentType.lastIndexOf("=")+1,ContentType.length());
    String strSub[]=FileData.split(strSplit); String strElement;
    int iBegin,iEnd;
    iBegin=0;iEnd=0;
    String FieldName,FieldValue;
    int bTrue;
    bTrue=0;
    int iPos;
    iPos=0;
    int iLocation;
    iLocation=0;
    for(int iIndex=0;iIndex<strSub.length;iIndex++)
    {
    strElement=strSub[iIndex];
    iBegin=strElement.indexOf("name=\"",0);
    if(iBegin!=-1)
    {
    iEnd=strElement.indexOf("\"",iBegin+6);
    FieldName=strElement.substring(iBegin+6,iEnd);
    iBegin=strElement.indexOf("filename=\"",0);
    if(iBegin!=-1)
    {
    bTrue=1;
    }
    //
    iEnd=strElement.indexOf("\r\n\r\n",0);
    if(bTrue==1)
    {
    iLocation=0;
    iPos=FileData.indexOf("filename=\"",iPos);
    iPos=FileData.indexOf("\n",iPos)+1;
    iPos=FileData.indexOf("\n",iPos)+1;
    iPos=FileData.indexOf("\n",iPos)+1;
    iLocation=FileData.indexOf(strSplit,iPos)-4;
    FieldValue=FileData.substring(iPos,iLocation);
    byte[] Byte_File_=FieldValue.getBytes();
    Byte_File=new byte[Byte_File_.length];
    for(int kIndex=0;kIndex<Byte_File_.length;kIndex++)
    {
    Byte_File[kIndex]=Buffer[iPos+6+kIndex];
    }
    session.putValue(FieldName,Byte_File);
    }
    else
    {
    FieldValue=strElement.substring(iEnd+4);
    session.putValue(FieldName,FieldValue.substring(0,FieldValue.indexOf("\n")-1));
    }
    bTrue=0;
    }
    }
    //数据处理结束
    String TypeValue,Id;
    TypeValue=(String)session.getValue("TypeValue");
    if(TypeValue!=null)
    {
    int iDoAction;
    iDoAction=0;
    if(TypeValue.indexOf("Add",0)!=-1)
    {iDoAction=1;}
    if(TypeValue.indexOf("Modify")!=-1)
    {iDoAction=2;}
    if(TypeValue.indexOf("Del")!=-1)
    {iDoAction=3;}
    odbcQuery="";
    Id=(String)session.getValue("RecordId");
    switch(iDoAction)
    {
    case 1:
    odbcQuery="insert into Link(SiteName) values(null)";
    odbcStmt.executeUpdate(odbcQuery);
    odbcQuery="select * from Link";
    odbcRs=odbcStmt___.executeQuery(odbcQuery);
    odbcRs.last();
    odbcRs.updateString("SiteName",(String)session.getValue("SiteName"));
    odbcRs.updateString("SiteURL",(String)session.getValue("SiteURL"));
    byte[] m_ByteArray=(byte[])session.getValue("SiteLogo");
    odbcRs.updateBinaryStream("SiteLogo",new ByteArrayInputStream(m_ByteArray),m_ByteArray.length);
    odbcRs.updateRow();
    response.sendRedirect("/System/Link/List.jsp");
    break;
    case 2:
      

  2.   

    上传没有问题啊,我可以用PLSQL Developer导出来,显示就是正常的