如何将SSI与Spring-boot一起使用



我有一个简单的"单个"页面应用程序,其中包含许多JavaScript和Jqueryui对话框。我正在为REST API使用Spring-Boot,目前从/Resources/public文件夹中传递 *.html页面。我现在想将" jqueryui"对话框提取到单独的文件中以使代码清洁器,但是我没有找到一种简单的方法来使它们作为服务器端所包含。我希望仅将嵌入式的tomcat指令用于SSI:https://tomcat.apache.org/tomcat-7.0.0.0-doc/ssi-howto.html但这似乎没有得到评估。我是否错过了应用程序中的某些配置。

rich p的答案使我想起了这个旧问题,当我找到替代解决方案时,我决定将其添加为答案,以防其他人有类似的问题:

我发现的一种方法是使用胸腺或更精确的页面布局。这样,我可以在单独的HTML文件中定义摘要,并添加th:fragment属性。然后可以将这些包含在具有th:insertth:replace的其他文件中。检查第二个链接以获取有关如何使用它的示例。

(授予您这是一个古老的问题... (

也许您可以使用另一个SO页面上的建议之一注册Tomcat过滤器(SSIFILTER(。例如,HAIM(批准的(解决方案包括在下面的代码上注册过滤器。我唯一没有立即看到的与您的用例相关的一点是如何配置SSIFilter:(

下面的代码是猜想 - 我实际上没有尝试过。我一直在调查是否有可能做您要问的事情,这是一个风险评估问题。我有兴趣 - 您实际上是否实现了这一点?有人吗?

    import org.apache.catalina.ssi.SSIFilter;
    @Bean
    public FilterRegistrationBean someFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(someFilter());
        registration.addUrlPatterns("/url/*");
        registration.addInitParameter("paramName", "paramValue");
        registration.setName("someFilter");
        registration.setOrder(1);
        return registration;
    } 
    public Filter someFilter() {
        // SSIFilter filt = new SSIFilter();
        // ..create and configure the  new SSIFilter() ...
        Filter filt = new SSIFilter() {
            public void reconfigure( FilterConfig config ) {
                this.config = config;
                // reconfigure only what you care about
                this.allowExec = config.allowExec;
                this.contentTypeRexEx = config.contentTypeRegEx;
                this.debug = config.debug;
                this.expires = config.expires;
                this.isVirtualWebappRelative = config.isVirtualWebappRelative;
            }
        };
        /*
            From:  https://tomcat.apache.org/tomcat-7.0-doc/ssi-howto.html 
            contentType - A regex pattern that must be matched before SSI processing is applied.
                When crafting your own pattern, don't forget that a mime content type
                may be followed by an optional character set in the form "mime/type;
                charset=set" that you must take into account. Default is
                "text/x-server-parsed-html(;.*)?".
            debug - Debugging detail level for messages logged by this servlet. Default 0.
            expires - The number of seconds before a page with SSI directives will expire.
                Default behaviour is for all SSI directives to be evaluated for every request.
            isVirtualWebappRelative - Should "virtual" SSI directive paths be interpreted
                as relative to the context root, instead of the server root? Default false.
            allowExec - Is the exec command enabled? Default is false.
         */
        FilterConfig fcfg = new FilterConfig() {
            public FilterConfig withChanges( boolean allowExec, Pattern contentTypeRegEx, int debug, Long expires, boolean isVirtualWebappRelative ) {
                this.allowExec = allowExec;
                this.contentTypeRegEx = contentTypeRegEx;
                this.debug = debug;
                this.expires = expires;
                this.isVirtualWebappRelative = isVirtualWebappRelative;
            }
        };
        filt.reconfigure(
            fcfg.withChanges(
                false,
                "text/x-server-partsed-html(;.*)?",
                java.util.logging.Level.FINEST.intValue(),
                (Instant.now().getEpochSecond() + (24*60*60)),
                false
            )
        );
        // ok hopefully that configured it!
        return filt;
    }

最新更新