With the html as follows:
<img src="/myWebAppContext/myAction!default.action />
xwork.xml could be as follows:
<xwork>
...
<result-types>
<result-type name="myBytesResult" class="foo.bar.MyBytesResult" />
</result-types>
...
<action name="myAction" class="...">
<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>
...
</xwork>
the action could be as follows:
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() { ... }
}
public class MyBytesResult implements Result {
public void execute(ActionInvocation invocation) throws Exception {
MyAction action = (MyAction) invocation.getAction();
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType(action.getContentType());
response.setContentLength(action.getContentLength());
response.getOutputStream().write(action.getImageInBytes());
response.getOutputStream().flush();
}
}