MultipartResponse. Servlet generating "normal" web page (pics + text)

Discussion in 'Java' started by Paul Smith, Nov 21, 2003.

  1. Paul  Smith

    Paul Smith Guest

    Hello,

    I am trying to teach myself about JSPs and Servlets. I decided to
    create a web application that allows me to enter some search criteria
    and display the results in the form of a list of items comprising some
    text and a picture (like any of the shopping sites on the web).

    I thought I might use the O'Reilly MultipartResponse class as I saw
    that you could have several different content types for the same
    response, and I guessed I needed text/plain and images/jpeg on the
    same page. It turns out that IE does not support multi-part responses,
    which made me realise that I must be going down the wrong track using
    the MultipartResponse object. After all, I use IE and can use online
    shopping sites just fine.

    Could someone tell me, at a high level summary level, how such sites
    are created. I want to store pictures in a database and retrieve them
    and their description in response to a user search and present a list
    of the results, with the pictures and descriptions side-by-side, in
    the user's browser.

    Many thanks,
    Paul
     
    Paul Smith, Nov 21, 2003
    #1
    1. Advertising

  2. Paul Smith wrote:

    > Hello,
    >
    > I am trying to teach myself about JSPs and Servlets. I decided to
    > create a web application that allows me to enter some search criteria
    > and display the results in the form of a list of items comprising some
    > text and a picture (like any of the shopping sites on the web).
    >
    > I thought I might use the O'Reilly MultipartResponse class as I saw
    > that you could have several different content types for the same
    > response, and I guessed I needed text/plain and images/jpeg on the
    > same page. It turns out that IE does not support multi-part responses,
    > which made me realise that I must be going down the wrong track using
    > the MultipartResponse object. After all, I use IE and can use online
    > shopping sites just fine.
    >
    > Could someone tell me, at a high level summary level, how such sites
    > are created. I want to store pictures in a database and retrieve them
    > and their description in response to a user search and present a list
    > of the results, with the pictures and descriptions side-by-side, in
    > the user's browser.
    >
    > Many thanks,
    > Paul


    Create html like this:

    ...
    <p>text retrieved from the db</p>
    <img src="http://yourhost/image?id=xxx/">
    ....

    Make image a servlet that sets its content-type to image/jpeg, read the image
    from the db using the id parameter and write the image out in the response.

    --
    Regards,
    Christophe Vanfleteren
     
    Christophe Vanfleteren, Nov 22, 2003
    #2
    1. Advertising

  3. Paul  Smith

    Sudsy Guest

    Re: MultipartResponse. Servlet generating "normal" web page (pics+ text)

    Paul Smith wrote:
    > Hello,
    >
    > I am trying to teach myself about JSPs and Servlets. I decided to
    > create a web application that allows me to enter some search criteria
    > and display the results in the form of a list of items comprising some
    > text and a picture (like any of the shopping sites on the web).
    >
    > I thought I might use the O'Reilly MultipartResponse class as I saw
    > that you could have several different content types for the same
    > response, and I guessed I needed text/plain and images/jpeg on the
    > same page. It turns out that IE does not support multi-part responses,
    > which made me realise that I must be going down the wrong track using
    > the MultipartResponse object. After all, I use IE and can use online
    > shopping sites just fine.

    <snip>
    > Many thanks,
    > Paul


    My, my! Go to www.w3c.org and read all about HTML and HTTP. You
    don't send all the parts of a page as a response; you include
    links to content in your HTML (M stands for "markup" after all)
    and it's up to the browser to pull it down.
    I don't know how/if you can do this in IE but in Netscape Ctrl-I
    displays all the forms, links, media (images and the like) in a
    page.
    If you don't comprehend the underlying protocol then choosing a
    particular class (Mutlipart Response) to solve an undefined
    problem seems a bit of a stretch...
    YMMV
     
    Sudsy, Nov 22, 2003
    #3
  4. Paul  Smith

    Paul Smith Guest

    Thank you both for your replies. So if I have images in a database, my
    servlet needs to read them from the database, write them out to files,
    and then include links to those files in the HTML the servlet
    produces?

    Paul
     
    Paul Smith, Nov 25, 2003
    #4
  5. Re: MultipartResponse. Servlet generating "normal" web page (pics+ text)

    Paul Smith wrote:
    > Thank you both for your replies. So if I have images in a database, my
    > servlet needs to read them from the database, write them out to files,
    > and then include links to those files in the HTML the servlet
    > produces?


    Absolutely no. First of all, I would seriously consider removing the images from
    the database and having them as files in the first place, because keeping them
    in the DB is just a giant performance killer if you don't need the transactional
    safety.

    In the unlikely case that the images really need to be in the DB, writing them to
    files on demand could form a cache, mitigating the performance loss, but it would
    also require cache management in order not to keep displaying older versions,
    and there would be timing problems.
    All in all, it sound like a bigger headache than it's worth. The alternative is
    to have the HTML page include links not to file but to another servlet, which
    reads the image from the DB and returns it directly as binary data.
     
    Michael Borgwardt, Nov 25, 2003
    #5
  6. Paul  Smith

    johannsig

    Joined:
    May 22, 2012
    Messages:
    1
    I think you need to step back a bit and just think of JSP pages as plain old HTML pages with a bunch of <% %> scriptlet tags capable fo performing logic on the server side before being delivered to the user.

    So if you want to show an image from your photo collection on your JSP page, just write:

    <img src="http://www.velocityreviews.com/forums/images/photos/photo_1.jpg" /> .. like usual - with plain HTML.

    But if you want a random image from your entire collection of 3000 photos to be displayed whenever the page is opened, instead write:

    <img src="http://www.velocityreviews.com/forums/images/photos/photo_<%=new Random().nextInt(3000) + 1 %>.jpg" /> ..

    There's a lot more to JSP than Scriptlets of course, but the fun is getting there :) I knew nothing about JSP in December 2010 year ago and now (May 2012) I've got an entire board game running on it. Incidentally --> http://apps.facebook.com/sovereign :wink:

    Good luck!
    -JS


    EDIT: Noticed that this thread is 9 years old - how embarassing... Sure hope everyone's well.
     
    Last edited: May 22, 2012
    johannsig, May 22, 2012
    #6
    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. circuit_breaker
    Replies:
    2
    Views:
    2,061
    Jack Jia
    Apr 4, 2004
  2. Don Noll

    PREVENT COPYING WEB PICS HELP

    Don Noll, Jun 13, 2005, in forum: HTML
    Replies:
    35
    Views:
    4,611
    Joel Shepherd
    Jun 17, 2005
  3. Replies:
    3
    Views:
    493
  4. Replies:
    29
    Views:
    1,241
    Arne Vajhøj
    Mar 21, 2009
  5. Replies:
    0
    Views:
    115
Loading...

Share This Page