<%
// If you want to include the output in a JSP, you can call this JSP with the IMG tag.
//
// Image source, from file (file) or database (Database)
String from = Request.getParameter ("from") == NULL? ": Request.getParameter (" from "). Tostring ();
// Picture type, JPEG / GIF / BMP
String type = request.getParameter ("type") == NULL? ": Request.getParameter (" type "). Tostring ();
Response.reset ();
Response.setContentType ("Image /" Type);
Java.io.inputstream in = NULL;
// Method 1: Read the image file in a stream. Pic.jsp? From = file & type = jpeg & file = c: /img/test.jpg
IF (from.equals (") || from.equals (" file "))
{
IN = new java.io.fileinputStream (Request.getParameter ("src"). TOSTRING ());
}
ELSE / / mode 2: Read the current from the database. pic.jsp? from = Database & Type = JPEG & SRC = 168
{
Java.util.list List = dbwrapper.executeQuery
"SELECT Content from Image Where ID = '" Request.getParameter ("src"). Tostring () "'"
);
IF (list.size ()> 0)
{
IN = (inPutStream) ((java.util.map) list.get (0)). Get ("content"));
}
}
IF (in! = null)
{
Byte [] b = new byte [1024];
Int Len;
While ((len = in.read (b))! = -1)
{
Response.getOutputStream (). Write (b);
}
In.Close ();
}
%>