I need to be able to serve up an image to a customer based upon the branding of
their site. For example, they should get their logo when they ask for
logo.gif. I'm doing this by making the src attribute of the img tag point them
to "imageServer.jsp?name=logo.gif". This way I can serve up their image
without them being able to find out who our other customers are.
In the code below I've tried to remove all newlines because they were getting
inserted into the stream that goes back to the browser and causing the
resulting file to appear as something other than a gif image. Now the problem
is that the data which is sent to the browser is always exactly one byte larger
than the actual file as it sits on the hard drive. If I use 'lynx -dump
http://url/to/imageServer.jsp?name=logo.gif > /tmp/logo.gif' the file will be
one byte larger than it is on the web server. This extra byte must be getting
appended to the file because the browser will still display the gif correctly.
I think that the JSP server (Resin 1.2.b2) is appending one carriage return to
the end of the file.
I've considered leaving it alone as it appears to be working, but that's just
not my style.
I realize I could write this as a servlet, but I would prefer to use a JSP.
If anyone has any ideas on how I can tell Resin to stop sending that extra byte
I'd really like to hear it.
Thanks,
-M@
<%@ page import="javax.servlet.*, java.util.*, java.io.*" %><%
String filename = "/path/to/image/files/";
filename = filename.concat(request.getParameter("name"));
File image_file = new File(filename);
FileInputStream fio = new FileInputStream(image_file);
String filesize = String.valueOf(image_file.length());
byte[] buffer = new byte[Integer.parseInt(filesize)];
fio.read(buffer);
response.setHeader("Content-type", "image/gif");
response.setHeader("Content-length", filesize);
ServletOutputStream sos = response.getOutputStream();
sos.write(buffer);
sos.flush();%>
--
Matt Hixson
Aventail Corporation
Seattle, Washington
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets