请教各位前辈,关于servlet取出blob后的问题! 现在的项目需要取出oracle中的blob数据,然后输出到jsp页面中。我用的servlet取的值,如果是图片的话,我可以用<img src="servletname">取出,但是如果blob中是字符串的话,我怎样在jsp中显示出来。谢谢各位! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 很正常blob只是一个byte数组,把byte数组装换成字符,就要靠Java的String类,具体什么API自己看一下:-),记得给分哦 我是想传一个输出流,不是传byte数组,比如像图片一样<img src="servletname">下面是取出blob数据的代码:public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); String modeid = ""; /*********************************************************************** * 接受上文传递的图片ID号 * **********************************************************************/ try { modeid = request.getParameter("modeid"); DBsqlconnn db=new DBsqlconnn(); conn=db.getSqlConn(); stmt = conn.createStatement(); rs = stmt .executeQuery("select htmlval from t_zyzds_mode_html where modeid='" + modeid + "'"); //System.out.println(SQLString + "asdas"); // 执行SQL }// try catch (SQLException ex) { System.err.println("aq.executeUpdate:" + ex.getMessage()); } /*********************************************************************** * 将流读入字符数组中,并显示到客户端 **********************************************************************/ try { if (rs.next()) { in = rs.getBinaryStream("htmlval"); response.reset();// 返回在流中被标记过的位置 // int len=in.available();//得到文件大小 OutputStream toClient = response.getOutputStream(); byte[] P_Buf = new byte[len]; int i; while ((i = in.read(P_Buf)) != -1) { toClient.write(P_Buf, 0, i); } in.close(); toClient.flush();// 强制清出缓冲区 toClient.close(); System.out.println("取出了流!"); } else { System.out.println("系统出错"); } rs.close(); stmt.close(); conn.close(); System.out.println("已经清空连接资源!"); } catch (Exception e) { e.printStackTrace(); System.out.println("err,显示到客户端出错!"); } hibernate多表查询问题 JS乱码问题。。 急啊,,....一个窗口最小化的问题....在线等待..... [高分求助]java web中怎样使用tomcat中的会话管理功能 如何在jsp中加入ocx控件?又如何调用ocx控件中的函数? Tomcat配置问题 关于jsp的一个菜鸟问题请教下大家 webservice远程调用 jsp:useBean的问题.如何在页面取Bean里的二维数组,并在页面把数组的元素打印出来?我很着急. jdbc的问题 有JSP的QQ群吗?? 简单JSTL逻辑怎么一直报错?
下面是取出blob数据的代码:public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { response.setContentType("text/html");
String modeid = "";
/***********************************************************************
* 接受上文传递的图片ID号
*
**********************************************************************/
try { modeid = request.getParameter("modeid");
DBsqlconnn db=new DBsqlconnn();
conn=db.getSqlConn();
stmt = conn.createStatement();
rs = stmt
.executeQuery("select htmlval from t_zyzds_mode_html where modeid='"
+ modeid + "'");
//System.out.println(SQLString + "asdas");
// 执行SQL
}// try
catch (SQLException ex) {
System.err.println("aq.executeUpdate:" + ex.getMessage()); }
/***********************************************************************
* 将流读入字符数组中,并显示到客户端
**********************************************************************/
try {
if (rs.next()) {
in = rs.getBinaryStream("htmlval");
response.reset();// 返回在流中被标记过的位置
// int len=in.available();//得到文件大小
OutputStream toClient = response.getOutputStream();
byte[] P_Buf = new byte[len];
int i;
while ((i = in.read(P_Buf)) != -1) {
toClient.write(P_Buf, 0, i);
}
in.close();
toClient.flush();// 强制清出缓冲区
toClient.close();
System.out.println("取出了流!");
} else {
System.out.println("系统出错");
}
rs.close();
stmt.close();
conn.close();
System.out.println("已经清空连接资源!");
} catch (Exception e) {
e.printStackTrace();
System.out.println("err,显示到客户端出错!");
}