org.apache.struts2.result

## Class PlainTextResult

- java.lang.Object
- - org.apache.struts2.result.StrutsResultSupport
  - - org.apache.struts2.result.PlainTextResult

- All Implemented Interfaces:
    Serializable, Result, StrutsStatics

      public class PlainTextResult
      extends StrutsResultSupport

  A result that send the content out as plain text. Useful typically when needed to display the raw content of a JSP or Html file for example.
  - location (default) = location of the file (jsp/html) to be displayed as plain text.
  - charSet (optional) = character set to be used. This character set will be used to set the response type (eg. Content-Type=text/plain; charset=UTF-8) and when reading using a Reader. Some example of charSet would be UTF-8, ISO-8859-1 etc.

       <action name="displayJspRawContent" >
         <result type="plainText">/myJspFile.jsp</result>
       </action>

       <action name="displayJspRawContent" >
         <result type="plainText">
            <param name="location">/myJspFile.jsp</param>
            <param name="charSet">UTF-8</param>
         </result>
       </action>

  See Also:
    Serialized Form

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface com.opensymphony.xwork2.Result

      `Result.LegacyAdapter`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `BUFFER_SIZE`

    - ### Fields inherited from class org.apache.struts2.result.StrutsResultSupport

      `DEFAULT_PARAM, DEFAULT_URL_ENCODING, parseLocation`

    - ### Fields inherited from interface org.apache.struts2.StrutsStatics

      `ACTION_MAPPING, HTTP_REQUEST, HTTP_RESPONSE, PAGE_CONTEXT, SERVLET_CONTEXT, SERVLET_DISPATCHER, STRUTS_ACTION_TAG_INVOCATION, STRUTS_PORTLET_CONTEXT`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `PlainTextResult()`
    `PlainTextResult(String location)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected String` | `adjustLocation(String location)`
    `protected void` | `applyAdditionalHeaders(javax.servlet.http.HttpServletResponse response)`
    `protected void` | `applyCharset(Charset charset, javax.servlet.http.HttpServletResponse response)`
    `protected void` | `doExecute(String finalLocation, ActionInvocation invocation)`
    `String` | `getCharSet()` Set the character set
    `protected void` | `logWrongStream(String finalLocation, InputStream resourceAsStream)`
    `protected Charset` | `readCharset()`
    `protected InputStream` | `readStream(ActionInvocation invocation, String location)`
    `protected void` | `sendStream(PrintWriter writer, InputStreamReader reader)`
    `void` | `setCharSet(String charSet)` Set the character set

    - ### Methods inherited from class org.apache.struts2.result.StrutsResultSupport

      `conditionalParse, conditionalParseCollection, doExecute, execute, getLastFinalLocation, getLocation, setEncode, setLocation, setParse`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface com.opensymphony.xwork2.Result

      `adapt, execute`

- - ### Field Detail

    - #### BUFFER_SIZE

          public static final int BUFFER_SIZE

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### PlainTextResult

          public PlainTextResult()

    - #### PlainTextResult

          public PlainTextResult(String location)

  - ### Method Detail

    - #### getCharSet

          public String getCharSet()

      Set the character set
      Returns:
        The character set

    - #### setCharSet

          public void setCharSet(String charSet)

      Set the character set
      Parameters:
        `charSet` - The character set

    - #### doExecute

          protected void doExecute(String finalLocation,
                                   ActionInvocation invocation)
                            throws Exception

      Overrides:
        `doExecute` in class `StrutsResultSupport`
      Throws:
        `Exception`

    - #### readStream

          protected InputStream readStream(ActionInvocation invocation,
                                           String location)

    - #### logWrongStream

          protected void logWrongStream(String finalLocation,
                                        InputStream resourceAsStream)

    - #### sendStream

          protected void sendStream(PrintWriter writer,
                                    InputStreamReader reader)
                             throws IOException

      Throws:
        `IOException`

    - #### adjustLocation

          protected String adjustLocation(String location)

    - #### applyAdditionalHeaders

          protected void applyAdditionalHeaders(javax.servlet.http.HttpServletResponse response)

    - #### applyCharset

          protected void applyCharset(Charset charset,
                                      javax.servlet.http.HttpServletResponse response)

    - #### readCharset

          protected Charset readCharset()

Copyright © 2000–2025 Apache Software Foundation. All rights reserved.