Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > MultipartResponse. Servlet generating "normal" web page (pics + text)

Reply
Thread Tools

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

 
 
Paul Smith
Guest
Posts: n/a
 
      11-21-2003
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
 
Reply With Quote
 
 
 
 
Christophe Vanfleteren
Guest
Posts: n/a
 
      11-22-2003
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
 
Reply With Quote
 
 
 
 
Sudsy
Guest
Posts: n/a
 
      11-22-2003
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

 
Reply With Quote
 
Paul Smith
Guest
Posts: n/a
 
      11-25-2003
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
 
Reply With Quote
 
Michael Borgwardt
Guest
Posts: n/a
 
      11-25-2003
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.

 
Reply With Quote
 
johannsig johannsig is offline
Junior Member
Join Date: May 2012
Posts: 1
 
      05-22-2012
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

Good luck!
-JS


EDIT: Noticed that this thread is 9 years old - how embarassing... Sure hope everyone's well.
 

Last edited by johannsig; 05-22-2012 at 12:51 PM.. Reason: Answered a 9 year old thread
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to invoke a servlet generating an image ? fabien.moquet@gmail.com Java 2 05-17-2007 10:16 PM
Servlet question(Tomcat, web.xml, servlet-class, servlet-name) circuit_breaker Java 2 04-04-2004 03:26 AM
Tomcat: POST from one servlet or internal class to another servlet Sean Clarke Java 1 01-07-2004 02:22 PM
how to get my servlet configuration before the servlet is initialised Andy Fish Java 4 12-17-2003 09:47 PM
Servlet generating jsp page Dieter Salath? Java 7 10-30-2003 02:02 PM



Advertisments