Child pages
  • How can we display dynamic or static images that can be provided as an array of bytes
Skip to end of metadata
Go to start of metadata

To display an image represented as an array of bytes

  • 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

<img src="/myWebAppContext/" />

Provide Helper Methods
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


        <result-type name="myBytesResult" class="MyBytesResult" />
    <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>

public class MyBytesResult implements Result {

	public void execute(ActionInvocation invocation) throws Exception {

		MyAction action = (MyAction) invocation.getAction();
		HttpServletResponse response = ServletActionContext.getResponse();



  • No labels