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. Advertisements

  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. Advertisements

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,634
    Laurent Bugnion
    Feb 9, 2006
  2. Greg Johnson
    Replies:
    4
    Views:
    3,351
  3. circuit_breaker
    Replies:
    2
    Views:
    2,400
    Jack Jia
    Apr 4, 2004
  4. David Elliott
    Replies:
    11
    Views:
    803
    David Dorward
    Feb 19, 2004
  5. Replies:
    1
    Views:
    1,845
    Alex Hunsley
    Mar 23, 2007
  6. pheadxdll
    Replies:
    16
    Views:
    5,719
    Neredbojias
    Jun 6, 2007
  7. Soren Vejrum
    Replies:
    4
    Views:
    1,018
    Lasse Reichstein Nielsen
    Jul 5, 2003
  8. Burak Gunay
    Replies:
    9
    Views:
    168
    Thomas 'PointedEars' Lahn
    May 25, 2006
Loading...