org.apache.struts2.views.jasperreports

## Class JasperReportsResult

- java.lang.Object
- - org.apache.struts2.result.StrutsResultSupport
  - - org.apache.struts2.views.jasperreports.JasperReportsResult

- All Implemented Interfaces:
    Serializable, Result, StrutsStatics, JasperReportConstants

      public class JasperReportsResult
      extends StrutsResultSupport
      implements JasperReportConstants

  Generates a JasperReports report using the specified format or PDF if no format is specified.

  This result type takes the following parameters:

  - location (default) - the location where the compiled jasper report definition is (foo.jasper), relative from current URL.
  - dataSource (required) - the EL expression used to retrieve the datasource from the value stack (usually a List).
  - parse - true by default. If set to false, the location param will not be parsed for EL expressions.
  - format - the format in which the report should be generated. Valid values can be found in `JasperReportConstants`. If no format is specified, PDF will be used.
  - contentDisposition - disposition (defaults to "inline", values are typically filename="document.pdf").
  - documentName - name of the document (will generate the http header `Content-disposition = X; filename=X.[format]`).
  - delimiter - the delimiter used when generating CSV reports. By default, the character used is ",".
  - imageServletUrl - name of the url that, when prefixed with the context page, can return report images.
  - reportParameters - (2.1.2+) OGNL expression used to retrieve a map of report parameters from the value stack. The parameters may be accessed in the report via the usual JR mechanism and might include data not part of the dataSource, such as the user name of the report creator, etc.
  - exportParameters - (2.1.2+) OGNL expression used to retrieve a map of JR exporter parameters from the value stack. The export parameters are used to customize the JR export. For example, a PDF export might enable encryption and set the user password to a string known to the report creator.
  - connection - (2.1.7+) JDBC Connection which can be passed to the report instead of dataSource
  - wrapField - (2.3.18+) defines if fields should warp with ValueStackDataSource see https://issues.apache.org/jira/browse/WW-3698 for more details

  This result follows the same rules from `StrutsResultSupport`. Specifically, all parameters will be parsed if the "parse" parameter is not set to false.

  Example:

       <result name="success" type="jasper">
         <param name="location">foo.jasper</param>
         <param name="dataSource">mySource</param>
         <param name="format">CSV</param>
       </result>

  or for pdf

       <result name="success" type="jasper">
         <param name="location">foo.jasper</param>
         <param name="dataSource">mySource</param>
       </result>

  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
    --- | ---
    `protected String` | `connection` Connection which can be passed to the report instead od dataSource.
    `protected String` | `contentDisposition`
    `protected String` | `dataSource`
    `protected String` | `delimiter`
    `protected String` | `documentName`
    `protected String` | `exportParameters` Names an exporter parameters map stack value, allowing the use of custom export parameters.
    `protected String` | `format`
    `protected String` | `imageServletUrl`
    `protected String` | `reportParameters` Names a report parameters map stack value, allowing additional report parameters from the action.
    `protected String` | `timeZone`
    `protected boolean` | `wrapField`

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

      `DEFAULT_PARAM, DEFAULT_URL_ENCODING, parseLocation`

    - ### Fields inherited from interface org.apache.struts2.views.jasperreports.JasperReportConstants

      `FORMAT_CSV, FORMAT_HTML, FORMAT_PDF, FORMAT_RTF, FORMAT_XLS, FORMAT_XML`

    - ### 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
    `JasperReportsResult()` Default ctor.
    `JasperReportsResult(String location)` Default ctor with location.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `doExecute(String finalLocation, ActionInvocation invocation)`
    `String` | `getConnection()`
    `String` | `getExportParameters()`
    `String` | `getImageServletUrl()`
    `String` | `getReportParameters()`
    `protected boolean` | `isAcceptableExpression(String expression)` Checks if expression doesn't contain vulnerable code
    `void` | `setConnection(String connection)`
    `void` | `setContentDisposition(String contentDisposition)`
    `void` | `setDataSource(String dataSource)`
    `void` | `setDelimiter(String delimiter)`
    `void` | `setDocumentName(String documentName)`
    `void` | `setExportParameters(String exportParameters)`
    `void` | `setFormat(String format)`
    `void` | `setImageServletUrl(String imageServletUrl)`
    `void` | `setNotExcludedAcceptedPatterns(NotExcludedAcceptedPatternsChecker notExcludedAcceptedPatterns)`
    `void` | `setReportParameters(String reportParameters)`
    `void` | `setTimeZone(String timeZone)`
    `void` | `setWrapField(boolean wrapField)`

    - ### 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

    - #### dataSource

          protected String dataSource

    - #### format

          protected String format

    - #### documentName

          protected String documentName

    - #### contentDisposition

          protected String contentDisposition

    - #### delimiter

          protected String delimiter

    - #### imageServletUrl

          protected String imageServletUrl

    - #### timeZone

          protected String timeZone

    - #### wrapField

          protected boolean wrapField

    - #### connection

          protected String connection

      Connection which can be passed to the report instead od dataSource.

    - #### reportParameters

          protected String reportParameters

      Names a report parameters map stack value, allowing additional report parameters from the action.

    - #### exportParameters

          protected String exportParameters

      Names an exporter parameters map stack value, allowing the use of custom export parameters.

  - ### Constructor Detail

    - #### JasperReportsResult

          public JasperReportsResult()

      Default ctor.

    - #### JasperReportsResult

          public JasperReportsResult(String location)

      Default ctor with location.
      Parameters:
        `location` - Result location.

  - ### Method Detail

    - #### setNotExcludedAcceptedPatterns

          public void setNotExcludedAcceptedPatterns(NotExcludedAcceptedPatternsChecker notExcludedAcceptedPatterns)

    - #### getImageServletUrl

          public String getImageServletUrl()

    - #### setImageServletUrl

          public void setImageServletUrl(String imageServletUrl)

    - #### setDataSource

          public void setDataSource(String dataSource)

    - #### setFormat

          public void setFormat(String format)

    - #### setDocumentName

          public void setDocumentName(String documentName)

    - #### setContentDisposition

          public void setContentDisposition(String contentDisposition)

    - #### setDelimiter

          public void setDelimiter(String delimiter)

    - #### setTimeZone

          public void setTimeZone(String timeZone)

      Parameters:
        `timeZone` - set time zone id

    - #### setWrapField

          public void setWrapField(boolean wrapField)

    - #### getReportParameters

          public String getReportParameters()

    - #### setReportParameters

          public void setReportParameters(String reportParameters)

    - #### getExportParameters

          public String getExportParameters()

    - #### setExportParameters

          public void setExportParameters(String exportParameters)

    - #### getConnection

          public String getConnection()

    - #### setConnection

          public void setConnection(String connection)

    - #### doExecute

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

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

    - #### isAcceptableExpression

          protected boolean isAcceptableExpression(String expression)

      Checks if expression doesn't contain vulnerable code
      Parameters:
        `expression` - of result
      Returns:
        true|false
      Since:
        6.0.0

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