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

Discussion in 'Java' started by ap, Feb 15, 2005.

  1. ap

    ap Guest

    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
    ap, Feb 15, 2005
    #1
    1. Advertising

  2. ap

    Ryan Stewart Guest

    "ap" <> wrote in message
    news:...
    > 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.
    Ryan Stewart, Feb 15, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve Richter

    <txt src= ...> equivalent of <img src= ...>

    Steve Richter, Feb 8, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    2,061
    Laurent Bugnion
    Feb 9, 2006
  2. Mikito Harakiri

    Redirect ServletOutputStream into a file?

    Mikito Harakiri, Apr 3, 2004, in forum: Java
    Replies:
    1
    Views:
    992
    Mikito Harakiri
    Apr 3, 2004
  3. David Elliott
    Replies:
    11
    Views:
    603
    David Dorward
    Feb 19, 2004
  4. pheadxdll
    Replies:
    16
    Views:
    3,612
    Neredbojias
    Jun 6, 2007
  5. Burak Gunay
    Replies:
    9
    Views:
    66
    Thomas 'PointedEars' Lahn
    May 25, 2006
Loading...

Share This Page