Servlet client code:
Package the servlet;
Import the Java. The awt. Image. BufferedImage;
Import the Java. IO. BufferedInputStream;
Import the Java. IO. BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
Import the Java. IO. InputStream;
Import the Java. SQL. Blob;
Import the Java. SQL. Connection;
Import the Java. SQL. The ResultSet;
Import Java, SQL Statement;
The import javax.mail. Imageio. Imageio;
The import javax.mail. Servlet. ServletException;
The import javax.mail. Servlet. ServletOutputStream;
The import javax.mail. Servlet. The annotation. WebServlet;
The import javax.mail. Servlet. HTTP. HttpServlet;
The import javax.mail. Servlet. HTTP. It;
import javax.servlet.http.HttpServletResponse;
The import com. Sun. Image. The codec. Jpeg. JPEGCodec;
The import com. Sun. Image. The codec. Jpeg. JPEGImageEncoder;
An import entity. The Course;
The import util. Shujuku;
/* *
* the Servlet implementation class showImgServlet
*/
@ WebServlet ("/showImgServlet ")
Public class showImgServlet extends the HttpServlet {
private static final long serialVersionUID=1L;
Protected void doPost (it request, HttpServletResponse response) throws ServletException, IOException {
//TODO Auto - generated method stub
String SQL="select image from PDate";
The Connection conn=Shujuku. Conn ();
The Statement st=null;
The ResultSet rs=null;
Try {
St=conn. CreateStatement ();
Rs=st. executeQuery (SQL);
While (rs), next ()) {
Blob Blob=rs. GetBlob (" image ");//this is pick up a BLOB values in weblogic environment
InputStream in=blob. GetBinaryStream ();//generated input stream
BufferedImage bimage=null;//cache the image object
BufferedInputStream ins=new BufferedInputStream (in);//input stream generated cache
Bimage=ImageIO. Read (ins);//read the ImageIO object into the cache object images, ImageIO is an important object
FileOutputStream SOS=new FileOutputStream (new File (" D:/1. JPG "));
BufferedOutputStream bos=new BufferedOutputStream (SOS);//generated output caching
JPEGImageEncoder encoder=JPEGCodec. CreateJPEGEncoder (bos);//generated JPEG image object
Encoder. Encode (bimage);//according to the format of the image code stream
Bos. Close ();
sos.close();
}
} the catch (Exception e) {
e.printStackTrace();
} the finally {
Shujuku. Close (rs, st, conn);
}
}
}
JSP shows:
<% @ page language="Java" contentType="text/HTML. Charset=utf-8 "
PageEncoding="utf-8" % & gt;
<% @ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" % & gt;
<meta HTTP - equiv="content-type" Content="text/HTML. Charset=ISO - 8859-1 "& gt;
<style>
TB, td {
border: 1px solid black;
The font - size: 22 px;
}
</style>
<body>