This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is there a solution?

 
Arun Somasundaram
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • 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?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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: 63
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64623
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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: 63
  • Mark post as helpful
  • send pies
  • 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 ]
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • 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 ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arun,
Please see:UseAMeaningfulSubjectLine

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