aspose file tools*
The moose likes Java in General and the fly likes StringBuffer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "StringBuffer" Watch "StringBuffer" New topic
Author

StringBuffer

cathymala louis
Ranch Hand

Joined: Nov 02, 2005
Posts: 77
Hi

I am having the data in the StringBuffer. I want to know how to display it in the web browser. I can able to display it in the console but not in the web browser. Please help me. Thanks in Advance.

Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3697
    
    5

You need to host the file on some kind of server and transmit it via JSP or Servlets. Have you set up a Java or J2EE servlet before? I'd download and try Tomcat out, then try some JSP writing tutorials. Once you've got that covered you can output the string buffer data pretty easily.

Alternatively, if you have a non-java server you could have the java program generate the string buffer as an HTML file that the server than serves but this solution isn't usually very useful especially if the file changes based on certain inputs like user information/state.


My Blog: Down Home Country Coding with Scott Selikoff
cathymala louis
Ranch Hand

Joined: Nov 02, 2005
Posts: 77
Hi

I tried as follows: Converting StringBuffer to String and using getBytes method getting the byte and storing it in the byte array and passing that byte array to the jsf.

sb - StringBuffer
b - byte array.

b = sb.toString().getBytes();

It is showing the error.
java.net.SocketException: Connection reset by peer: socket write error

The StringBuffer can't be transferred like that.

Thanks in Advance.

Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
You should try to be more forthcoming with information, rather than
mentioning things like "jsf" in passing! If you are indeed using JSF,
I would have a backing bean expose a property of type String and then
just access that string, for example:
In your backing bean class, you can implement this any way you like,
for example, with a StringBuffer:
[ November 21, 2005: Message edited by: Jeff Albrechtsen ]

There is no emoticon for what I am feeling!
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3697
    
    5

All java Objects, especially StringBuffer, have a toString() method that converts it to java String. I'm not sure why'd you need to transmit it as a byte array.
cathymala louis
Ranch Hand

Joined: Nov 02, 2005
Posts: 77
Hi

Let me explain more clear.

I need to display an image. Trying to convert image into byte array, so that I can display it in the web browser.

For a Single page it works fine. Since I need to display more than one page. I concatinating all the page contents into String Buffer, by using append method. It is appending fine.

Now my problem is how to convert StringBuffer into byte array.

So that I can display it in the web browser.

Thanks.


how to convert StringBuffer into byte array
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18127
    
    8

Remember that you are generating a page that can be interpreted by a browser. And browsers can't interpret pages that contain mixtures of text and binary data like images. When web designers want to "include" an image in a page, they do that by putting an <img> element in their page with a link to the image. They don't put the image itself into the page.

So you will have to do the same thing. If you are generating the image dynamically then your HTML will have to have an <img> element whose "src" attribute is a link to something (I would use a servlet) that returns only the binary data and nothing else.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
If you are indeed using JSF, why not just use h:graphicImage?
cathymala louis
Ranch Hand

Joined: Nov 02, 2005
Posts: 77
Hi

I am not displaying image from any particular location. The image I am getting is from IBM Content Manager. It has some java API. Using those API's the only way i can display images is using byte array. For a single page it works fine. Since need to display more pages used String buffer to append. Now wants to convert this StringBuffer into byte array so that i can display it in the browser.

Sorry for the confusion.
Thanks.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Finally! You've explained your context! Again, html use the <img> tag to embed images:

<img src="path"/>

Different web frameworks have their own tags to generate that html.

The typical bare-bones servlet/jsp solution is to map such paths to a servlet
that writes back the image. Any textbook on servlets/jsps will have an
example of that.

Now, it would be great if JSF had some way to bind a property to simplify this,
but I haven't seen that done. Anybody?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: StringBuffer
 
Similar Threads
Applet running on tomcat
setText doesn't display html!
Retrieve Images from oracle
How to increase the size of the <h:selectOneMenu> control.
how to call url