3

Struts 2 アプリのすべてのページに表示したい APVERSION、APPNAME、APPREV などの定数があります。

これらの要件により、その情報を servletContext のイントロに配置し、アプリのデプロイ時にこれをロードするのは素晴らしいことだと思いました。

実装するリスナーを作成しました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);
    }   
}

そしてweb.xml、リスナーに追加しました:

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

私の Tiles テンプレートに追加したもの:

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

しかし、ここでは何も得られません。

Struts 2 アクションから servletContext を取得すると、正しい値を読み取ることができるので、値は正常に設定されます。

私は何を間違っていますか?

4

1 に答える 1

0

使用できます

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

または

${appName}  -  ${appVer}
于 2014-04-26T05:46:13.613 に答える