Search code examples
javadependency-injectionstruts2xml-configuration

How to get struts.multipart.maxSize at runtime


Can be obtained at runtime the struts.multipart.maxSize value defined in struts.xml?

using Struts2

<dependency>
      <groupId>org.apache.struts</groupId>
      <artifactId>struts2-core</artifactId>
      <version>2.3.24.1</version>
</dependency>

Solution

  • It could be done the following way. Add this code to the action or bean managed by Struts container. For other beans you should use the container to inject dependencies.

    private String multipartMaxSize;
    
    @Inject(StrutsConstants.STRUTS_MULTIPART_MAXSIZE)
    public void setMultipartMaxSize(String multipartMaxSize) {
      this.multipartMaxSize = multipartMaxSize;
    }