You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Current »

Save the text string as an InputStream property

package actions;

import java.io.InputStream;
import java.io.StringBufferInputStream;
import com.opensymphony.xwork2.ActionSupport;

public class TextResult extends ActionSupport {

  private InputStream inputStream;
  public InputStream getInputStream() {
    return inputStream;
   }

  public String execute() throws Exception {
    inputStream = new StringBufferInputStream(
      "Hello World! This is a text string response from a Struts 2 Action.");	
    return SUCCESS;
  }
}

Specify a Stream Result type

<action name="text-result" class="actions.TextResult">
  <result type="stream">
     <param name="contentType">text/html</param>
     <param name="inputName">inputStream</param>
   </result>
</action>
  • No labels