How to configure Struts 2 to search for "action results" from both the class and WEB-INF?

Background

We have an existing webapp built with Struts 2 and Freemarker, from which Ive created an option by copying some of the code and templates. Kludgy but manageable. However, we will soon be releasing a few more options (which should be separate WARs), making copying inconsistent. My idea is to instead place all the shared materials in the jar included in each webapp: shared files could be stored in one place, and even better if this webapp could redefine files from the class path. So far I have been able to do this with code, but the Convention plugin makes the same difficult for Freemarker templates.

Problem

Until now, our webapp has relied on the Convention to find the results of Freemarker actions (i.e. templates) for actions when the application starts, saving us from the tedious annotation of each of them. If I followed correctly, the class DefaultResultMapBuilderis responsible for finding the results of actions; in particular, the method is createFromResourcesviewed in webapp, and then in the classpath for the template files corresponding to our actions.

This is exactly what I want - except that we put our templates under /WEB-INFto protect them from external access (using the constant struts.convention.result.pathin our Struts configuration). Until now, this has worked fine, with ALL the template files located under /WEB-INF, but do not work with the files also in the classpath. DefaultResultMapBuilderit can, of course, find files in the classpath, but only if the webapp templates are directly related to the context root, since any class templates should be in the package structure equivalent to the structure of the template directories under the context root. To get the results of actions when "struts.convention.result.path" begins with "/ WEB-INF /", you need a root package called "web-inf", but of course, hyphens are not allowed in package names.

( , TemplateLoader, . , , . , ...)

?

... /WEB-INF, Id, . , Id ( , ).

ResultMapBuilder, DefaultResultMapBuilder ( , - !), , Struts-plugin.xml Struts ( org.apache.struts2.convention.ResultMapBuilder bean), , , "/WEB-INF" , , , "/WEB-INF/" ServletContext.

, ? ?

+5

All Articles