Johnson nickel wrote:
Hi Evans,

          I digged in google examples in StreamResult. But, i can't
understand.
 I want to display the images in browser Using StremResult.

              Instead of ServletOutputStream out=
response.getOutputStream();
How can i use StreamResult.

        Can u give some examples pgm?? That will be helpful..
Regards,
Johnson
Hi Johnson, I think just need to read up a little more on Struts 2 as it seems you're trying to do too much yourself based on Struts1 experiences rather than let the framework do more of the routine work. Ian Roughly's book is a good place to start: http://www.infoq.com/minibooks/starting-struts2

Anyway, in a previous email you mentioned you know how to open an input stream from the image data in your database:

InputStream in = rs.getBinaryStream("filedata");

The StreamResult requires that an input stream is open and available in a public property in your action. Here's a section from your new action:

public class MyAction extends ActionSupport {
//....
private InputStream imageStream;

public String execute() {
  // read data from the database ...
  //...
 imageStream = rs.getBinaryStream("filedata");
  // ...
  return SUCCESS;
}

/** Return an InputStream for the StreamResult */
public InputStream getImageStream() {
  return imageStream;
}

That's it. We have an open InputStream in a public property in your action. You don't do anything other than prepare it for reading.

Now your struts.xml requires the action and result definition. The definition below states that when your action returns success, the stream result type (StreamResult) should be used and that the name of the InputStream property is imageStream (ie. getImageStream()). That ties it back into the code above.

<action name = "myaction" class="MyAction">
  <result name="success" type = "stream">
   <param name="contentType">image/jpeg</param>
   <param name="inputName">imageStream</param>
   <param name="contentDisposition">filename="image.jpg"</param>
   <param name="bufferSize">1024</param>
 </result>
</action>

Hope that helps. After you have that working, you can also experiment with getting the content type and filename from properties in your action.
Hint:  <param name="contentType">${contentType}</param>

Regards,
Jeromy Evans


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to