请教jsp中读取BLOB类型时,为何不能正常读取,读出来的文件不可用(在线等待中..)

lovelong1981 2003-10-08 11:47:58
本人用jsp读取BLOB数据类型时,文本文件可能用,但是像word和图片就没有办法取,word取出来都是乱码,图片取出来没有用,以下是jsp中原部分原文件。
我用的weblogic6.1,orcale9i,
Blob myblob = rs.getBlob("content");
String fileName = rs.getString("name");
System.out.println(fileName);
String mime = rs.getString("ctypes");
InputStream inStream = myblob.getBinaryStream();
long size = myblob.length();
int isize = (int)size;
byte pictureData[] = new byte[isize];
int bytes = inStream.read(pictureData);

response.setContentType(mime);
String serverName = request.getServerName();
String Location = "http://" + serverName + "/" + fileName;
response.setHeader("Content-Location",Location);
//图片输出的输出流
ServletOutputStream output = response.getOutputStream();
//将缓冲区的输入输出到页面
output.write(pictureData);
//输入完毕,清楚缓冲
output.flush();
output.close();

pass:如果有人知道asp连接9i的方法,请告诉我,
我从8i换成9i后,asp就连接不上,可能是驱动不对,那有Microsoft ODBC for oracle下载的地方
...全文
97 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
gjd111686 2003-10-08
  • 打赏
  • 举报
回复
是否是你的上载拆分出现了问题.
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:
lovelong1981 2003-10-08
  • 打赏
  • 举报
回复
还是一样的结果,为什么会这样呢?
lovelong1981 2003-10-08
  • 打赏
  • 举报
回复
不是吧,来拿分,也要给点意见吧,
gjd111686 2003-10-08
  • 打赏
  • 举报
回复
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();
}
hj12 2003-10-08
  • 打赏
  • 举报
回复
gz
thefishwilldie 2003-10-08
  • 打赏
  • 举报
回复
up 我也想听
lovelong1981 2003-10-08
  • 打赏
  • 举报
回复
上传没有问题啊,我可以用PLSQL Developer导出来,显示就是正常的
zwxu 2003-10-08
  • 打赏
  • 举报
回复
换一下驱动试试
duye 2003-10-08
  • 打赏
  • 举报
回复
应该是上传的时候不正确。二进制文件上传的时候需要编码的或者解码的

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧