Class Compress

java.lang.Object
org.apache.struts2.components.Component
org.apache.struts2.components.Compress

public class Compress extends Component

Used to compress HTML output. Just wrap a given section with the tag.

Security considerations:

  • Body content is truncated in log messages to prevent sensitive data exposure
  • Maximum size limit prevents DoS attacks via large inputs (configurable via struts.tag.compress.maxSize)
  • Regex operations include safeguards against ReDoS attacks

Configurable attributes are:

  • force (true/false) - always compress output, this can be useful in DevMode as devMode disables compression

Examples

  
  <s:compress>
    <s:form action="submit">
    <s:text name="name" />
    ...
    </s:form>
  </s:compress>
  
 

Uses conditional compression depending on action

  
  <s:compress force="shouldCompress">
    <s:form action="submit">
    <s:text name="name" />
    ...
    </s:form>
  </s:compress>
  
 
"shouldCompress" is a field with getter define on action used in expression evaluation
Since:
7.2.0
  • Constructor Details

  • Method Details

    • setCompressionEnabled

      public void setCompressionEnabled(String compressionEnabled)
    • setMaxSize

      public void setMaxSize(String maxSize)
    • setLogMaxLength

      public void setLogMaxLength(String logMaxLength)
    • end

      public boolean end(Writer writer, String body)
      Description copied from class: Component
      Callback for the end tag of this component. Should the body be evaluated again?
      NOTE: will pop component stack.
      Overrides:
      end in class Component
      Parameters:
      writer - the output writer.
      body - the rendered body.
      Returns:
      true if the body should be evaluated again
    • usesBody

      public boolean usesBody()
      Description copied from class: Component
      Overwrite to set if body should be used.
      Overrides:
      usesBody in class Component
      Returns:
      always false for this component.
    • setForce

      public void setForce(String force)