1

Image(.jpg) 以 blob 类型存储在数据库中。我已经编写了用于检索 blob 的代码

<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%>
<% Blob image = null;
java.sql.Connection con = null;
byte[ ] imgData = null ;
java.sql.Statement stmt = null;
java.sql.ResultSet rs = null;
 try {
System.out.println("DisplayBlob.jsp request Parameter "+request.getParameter("imgName"));
con = java.sql.DriverManager.getConnection("jdbc:oracle:thin:@ip:1521:sid","userName", "password");
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT blobObj FROM ImageBlobTable");
if (rs.next()) {
image = rs.getBlob(1);
imgData = image.getBytes(1,(int)image.length());
} else {
out.println("Display Blob Example");
out.println("image not found for given id>");
return;
}
response.setContentType("image/gif");
OutputStream o = response.getOutputStream();
o.write(imgData);
o.flush();
o.close();
} catch (Exception e) {
out.println("Unable To Display image");
out.println("Image Display Error=" + e.getMessage());
return;
} finally {
try {
rs.close();
stmt.close();
con.close();
 } catch (SQLException e) {
 e.printStackTrace();
 }
 }
 %>  

有 index.jsp。在这个 Jsp 中有文本,当用户将光标移到文本上时,我必须显示图像。当用户删除该文本上的光标时,图像应该消失。我怎样才能做到这一点?

技术:JSP,jquery

4

1 回答 1

1

将您的代码拆分为 servlet 以便像这样检索图像数据 + 下载,以及像这样通过 JavaScript 执行图像显示/隐藏的JSP

于 2012-08-29T19:48:17.693 回答