tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Josh G <j...@gfunk007.com>
Subject Image download?
Date Mon, 09 Feb 2004 23:58:35 GMT

Hi, I have a servlet that's trying to send image files instead of a html 
response that doesn't seem to be working. Here's the code in question:

                 //Set content-type
                 ServletContext context = getServletContext();
                 response.setContentType(context.getMimeType(media.getLocation()));

                 //Open file
                 try {
                         FileReader in = new FileReader(new 
File(media.getLocation()));

                         char[] buffer = new char[4096];
                         int rc;
                         PrintWriter out = response.getWriter();

                         //dump contents
                         for 
(rc=in.read(buffer,0,buffer.length);rc>0;rc=in.read(buffer,0,buffer.length))
                                 out.write(buffer,0,rc);

                         //Close file, and finish.

                         in.close();
                         return;

                 } catch (IOException e) {
                         Logger.debug(this,"IOException on media read/dump 
:(");
                         e.printStackTrace();
                         return;
                 }

Anybody out there know where I'm going wrong? Is it some sort of 
text<->binary thing in the java.io functions I didn't take into account?

Any help much appreciated!

Cheers,
-Josh


          "He likes to run, And then the thing with the.. person..
                ... Oh boy, that monkey is going to pay."

            [ Josh 'G' McDonald ]  --  [ Pirion Systems, Brisbane]

[ 07 3257 0490 ]  --  [ 0415 784 825 ]  --  [ http://www.gfunk007.com/ ] 


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message