Search code examples
nullpointerexceptionstruts2migrationactioncontext

Issue with ActionContext.getContext() returns null when migrating from Struts 2.5.33 to Struts 6.4.0


I am migrating from Struts 2.5.33 to Struts 6.4.0. After following the guide at https://cwiki.apache.org/confluence/display/WW/Struts+2.5+to+6.0.0+migration, the app could not display the homepage bcause of NullPointerException, which is due to ActionContext.getContext() returns null insides the Struts code.

In the JSP page, I printed out the value of ActionContext.getContext(), it was not null before migration, but is null after migration.

I followed all migration steps at https://cwiki.apache.org/confluence/display/WW/Struts+2.5+to+6.0.0+migration.

Any idea is much appreciated. Thanks.

Please see Stacktrace logs below


Solution

  • The root cause of the above error is

    org.apache.tiles.definition.NoSuchDefinitionException: Cannot find definition named 'loginForm'
        at org.apache.tiles.impl.mgmt.CachingTilesContainer.render(CachingTilesContainer.java:123) ~[tiles-core-3.0.8.jar:3.0.8]
    

    Solution: Add the below into web.xml

        <context-param>
        <param-name>org.apache.tiles.definition.DefinitionsFactory.DEFINITIONS_CONFIG</param-name>
        <param-value>/WEB-INF/tiles.xml</param-value>
      </context-param> 
    

    https://lists.apache.org/thread/zoysvnb52zk4kv5rg445r5bd8rkn7hto https://issues.apache.org/jira/browse/WW-5419