Search code examples
javahtmlstruts2staticstatic-pages

How to return a HTML page from struts.xml itself without going to an action?


If a request is made to a HTML page, how to return it directly from struts.xml without going to an action?


Solution

  • Create an action that has a result in the struts.xml but doesn't have a class, i.e.

    <package name="default" extends="struts-default">
    
    <action name="index">
          <result name="myPage">/path/to/page.html</result>
    </action>
    

    You could also create a global result, that could be found from any action, i.e

    <global-results>
          <result name="myPage">/path/to/page.html</result>
    </global-results>
    
    <action name="index"/> 
    

    You could create an interceptor that returns a result while intercepting and action. These are essential elements of the configuration that invoke a dispatcher to forward to requested page.