Using ServletOutputStream in Servlet Vs <img src="../images/abc.gif" />

A

ap

Hi all,
Is anyone one know what is the different between them and which
one is faster or they have the same performance....

#############################################
public void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
response.setContentType("image/jpeg");
ServletOutputStream out = response.getOutputStream();
BufferedInputStream in = new BufferedInputStream(new
FileInputStream ("c:/images/abc.gif"));
while ((data = in.read()) != -1) {
out.write(data);
}
in.close();
out.close();
}
#############################################

and

#############################################
<img src="../images/abc.gif" /> in a .jsp file
#############################################

both of the file name are generated by some function
 
R

Ryan Stewart

ap said:
Hi all,
Is anyone one know what is the different between them and which
one is faster or they have the same performance....

#############################################
public void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
response.setContentType("image/jpeg");
ServletOutputStream out = response.getOutputStream();
BufferedInputStream in = new BufferedInputStream(new
FileInputStream ("c:/images/abc.gif"));
while ((data = in.read()) != -1) {
out.write(data);
}
in.close();
out.close();
}
#############################################
This sends a response to the client containing an image (with the wrong
Content-Type).
and

#############################################
<img src="../images/abc.gif" /> in a .jsp file
#############################################
This causes the client to send an HTTP request for an image.

I'm not sure what you're looking for. The two aren't really related. You could
use a servlet mapping to cause the former to be used to respond to the latter.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top