Brian Deeley

Greenhorn
+ Follow
since Jan 17, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Brian Deeley

Check out the Enerjy tools. Easy to set up, and they keep you inside your IDE.

[Changed HTML-reference to UBB code - Ilja]
[ January 21, 2005: Message edited by: Ilja Preuss ]
19 years ago
Ben,
Tomcat 4.x , It was the kind of thing that was a quick fix that was slipped into production
Worked good though, six months later we've had no problems with it. A bit slow if you try to load more than 5 jsp pics on a page.
19 years ago
JSP
Here is a sample JSP, DealerPicture makes a connection to a (My)SQL DB and retrieves the images stored as BLOBs.

The one trick I learned was to not have any white space in your JSP, as soon as your JSP compiler outputs an out.write("\r\n"); your sunk.



<%@ page contentType="image/jpeg" %><%@ page import="cc.deeley.picture.DealerPicture" %><%@ page import="java.util.*" %><%@ pageimport="java.io.*" %><%@ page import="org.apache.log4j.Logger" %><%! private static Logger logger = Logger.getLogger("cc.deeley.picture"); %><%
int BLOCK_SIZE_WRITE = 512;
String picKey = request.getParameter("picnum");
int picInt =0;
if ((picKey == null) || (picKey.length() == 0)) {
picKey = "Missing picKey parameter";
}
try {
picInt = Integer.parseInt(picKey);
}
catch (NumberFormatException nfe) {
logger.error( " bad picKey: " +picKey);
}

DealerPicture dp = new DealerPicture(picInt);
dp.fetchPic( dp.getPicKey() );

if ( ( dp.getMime().indexOf("jpeg")!= -1 ) || ( dp.getMime().indexOf("jpg")!= -1 ) ){
response.setContentType("image/jpeg");
}
else if ( dp.getMime().indexOf("gif")!= -1 ) {
response.setContentType("image/gif");
}
OutputStream os = response.getOutputStream();
ByteArrayInputStream bs = new ByteArrayInputStream( dp.getPicMass() ) ;
try {
// fs = new FileOutputStream(f);
byte[] buf = new byte[BLOCK_SIZE_WRITE];
int bytes;
while ((bytes = bs.read(buf)) != -1) {
os.write(buf, 0, bytes);
}
}
catch (IOException ex) {
logger.error(ex.toString());
}
finally {
if (os != null) try {os.close();} catch (Exception ex) {}
}
%>
19 years ago
JSP