• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Is there a solution?

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

My problem is I want to write the character text as well as the binary data to the client in a single servlet.

I have the images in the database.I want to organize the image with in a table and then send to the client.For writing binary data to the client we need ServletOutputStream object which can be obtained by calling response.getOutputStream() method,moreover the content type should be set as either



Then how to send the html to the client i.e the HTML code required to organize the binary data with in a table.For this we need to set the content type as response.setContentType("text/html") and a PrintWriter object is needed to write the character text.If I add the follwing code



with in the same servlet in which the binary data is sent to the client automatically the error occurs.

So what is the solution?
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The browser will send two requests, one for the image and another for the text. You CANNOT send both an image and text in the same response.
 
Arun Somasundaram
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Mr.David O'Meara for your suggesstions.I know both binary data and text cannot be sent in a single response,so I asked for the alternative.It will be helpful if you give a small example of how to make the browser to make two requests one for image and another for text.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The same way that you would in any other case, with <img> tags in the HTML.
 
Arun Somasundaram
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My browser does not renders the image.Here is the code:-


I can Only see the blank screen.




http://sun/profile/picture is the URL for the servlet which retrieves the image from the database and writes the binary data to the client.
[ September 05, 2006: Message edited by: Arun Somasundaram ]
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you certain that whatever the server sends back is a valid image? Have you tried accessing the image URL directly, saving the result to a file, and then viewing it?

Also note that you're talking about http://sun/profile/picture, while the code uses http://sun/jspbook/picture.
[ September 05, 2006: Message edited by: Ulf Dittmer ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Arun,
Please see:UseAMeaningfulSubjectLine

"Is there a solution?" tells us nothing about your question.
 
reply
    Bookmark Topic Watch Topic
  • New Topic