T
Ted
Hi everyone,
I'm having trouble with a servlet I'm working on. I'm trying to display
an image when you go to a url. When I go to the url on my local
computer it takes about 6 seconds to download an image that is about
20KB. Downloading the image (again, from my local computer) via just
apache (no java) takes no time at all. If I change the code to just
loop through the read and not print anything, it is also quite fast.
Anyone have any idea why this would be so slow?
So in short: it works, but it's too slow, any ideas?
Thanks!
Ted.
This is the code:
-----------------
String fn = new String("image.png");
File f = new File(fn);
response.setContentType(getServletContext().getMimeType(fn));
response.setContentLength((int) f.length());
FileInputStream in = new FileInputStream(f);
OutputStream out = response.getOutputStream();
byte[] buf = new byte[1024];
int cnt = 0;
while((cnt = in.read(buf)) >= 0)
out.write(buf, 0, cnt);
in.close();
out.flush();
out.close();
I'm having trouble with a servlet I'm working on. I'm trying to display
an image when you go to a url. When I go to the url on my local
computer it takes about 6 seconds to download an image that is about
20KB. Downloading the image (again, from my local computer) via just
apache (no java) takes no time at all. If I change the code to just
loop through the read and not print anything, it is also quite fast.
Anyone have any idea why this would be so slow?
So in short: it works, but it's too slow, any ideas?
Thanks!
Ted.
This is the code:
-----------------
String fn = new String("image.png");
File f = new File(fn);
response.setContentType(getServletContext().getMimeType(fn));
response.setContentLength((int) f.length());
FileInputStream in = new FileInputStream(f);
OutputStream out = response.getOutputStream();
byte[] buf = new byte[1024];
int cnt = 0;
while((cnt = in.read(buf)) >= 0)
out.write(buf, 0, cnt);
in.close();
out.flush();
out.close();