Struts2 ognl servlet context

I have some constants like APPVERSION, APPNAME and APPREV that I want to display on every page in my Struts 2 application.

With these requirements, I thought it would be great to host this info-servlet content and load it when deploying the application.

I created a listener that implements ServletContextListener

:

public class ApplicationInitListenerImpl extends GenericVsService implements ApplicationInitListener,ServletContextListener {

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
    }

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        ServletContext sc = sce.getServletContext();        
        sc.setAttribute("appVer",xxx.utils.VConstants.APPVER);
        sc.setAttribute("appName",xxx.utils.VConstants.APPNAME);       
        sc.setAttribute("appRev",xxx.utils.VConstants.APPREV);
    }   
}

      

and then I added to my web.xml

listener:

<listener>
        <listener-class>xxx.listeners.ApplicationInitListenerImpl</listener-class>
</listener>

      

In my Tiles template, I added:

<s:property value="#application.appName"/> - <s:property value="#application.appVer"/>

      

But I don't see anything here.

If I get the servletContext from a Struts 2 activity, I can read the correct values, so the values ​​are set in order.

What am I doing wrong?

+3


source to share


1 answer


you can use

<s:property value="#attr.appName"/> - <s:property value="#attr.appVer"/>

      



or

${appName}  -  ${appVer}

      

0


source







All Articles