Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • Reference an Action for the image src attribute
  • Provide a helper method on the Action to return an array of bytes
  • Provide a Result Type that renders the array to the response

Reference an Action

Code Block
xml
xml
titleMyAction.jsp
<img src="/myWebAppContext/myAction.do" />

Provide Helper Methods

Code Block
java
java
titleMyAction.java
public class MyAction extends ActionSupport {
  public String doDefault() {
    return "myImageResult";
  }

  public byte[] getMyImageInBytes() { .... }

  public String getMyContentType() { ... }
  public String getMyContentDisposition() { ... }
  public int getMyContentLength() { .... }
  public int getMyBufferSize() { ... }

}

Provide a Custom Result Type

Code Block
xml
xml
titlestruts.xml
<struts>

    ...
    <result-types>
        <result-type name="myBytesResult" class="MyBytesResult" />
    </result-types>
    ...
    <action name="myAction" class="MyAction">
        <result name="myImageResult" type="myBytesResult">
            <param name="contentType">${myContentType}</param>
            <param name="contentDisposition">${myContentDisposition}</param>
            <param name="contentLength">${myContentLength}</param>
            <param name="bufferSize">${myBufferSize}</param>
        <result>
    </action>
    ...

</struts>

...