- 论坛徽章:
- 0
|
Web服务器:
web1 tomcat
web2 Oracle Application Server
使用Blob,在Oracle数据库中的存储文件数据,然后在Web服务器1和2上访问存储的文件,在 web1
上能正常显示文件内容,但是在 web2 上得到的却是乱码。可以确定的是,存储到数据库这一过程没有
问题,以下是从db中检索blob,并得到文件内容的代码:
sql 文:
sql1 = SELECT Content FROM Ta_FILES where File_ID=0;
检索代码:
Statement stmt = con.createStatement();
ResultSet rs =
stmt.executeQuery(sql1);
while (rs.next()) { buf = rs.getBytes(1); }
rs.close();
stmt.close();
生成文件代码:(res HttpServletResponse)
byte[] bufFile = 检索代码的返回值;
res.setContentType("application/octet-stream");
res.setHeader("content-disposition", "attachment;filename= sFileName" );
OutputStream out = res.getOutputStream();
out.write(bufFile, 0, bufFile.length );
out.close();
打了一下log,发现,tomcat和oas在得到字节数组bufFile 时,使用new String(bufFile) 方法时,tomcat能正常显示文件的内容,但是oas不能,得到的乱码,也就是最后得到的乱码,
请问 ,怎么解决。 谢谢 |
|