Reputation: 7118
I have a simple "single" page app with a lot of JavaScript and jQueryUI Dialogs. I am using spring-boot for the REST API and currently deliver the *.html page(s) from the /resources/public folder. I now wanted to extract the jQueryUI Dialog divs into separate files to make the code cleaner, but I didn't find an easy way to just have them as server side includes. I was hoping to just use the embedded tomcat directives for SSI: https://tomcat.apache.org/tomcat-7.0-doc/ssi-howto.html But this doesn't seem to get evaluated. Do I miss some configuration in the application.properties or is there another easy way to achieve this?
Upvotes: 1
Views: 1732
Reputation: 7118
The answer from rich p
reminded me of this old question and as I found an alternate solution I decided to add this as an answer in case anyone else has a similar question:
One way I found is to use thymeleaf or more precise their page layouts. With this I can define snippets in separate HTML files and add the th:fragment
attribute. These can then be included in other files with th:insert
or th:replace
. Check the second link for examples on how to use it.
Upvotes: 1
Reputation: 975
( Grant you this is an ancient question... )
Perhaps you can register the Tomcat filter (SSIFilter) using one of the suggestions on this other SO page. For example, Haim's (approved) solution included registering a filter with code like that below. The only bit I didn't see right away, relevant to your use case, was how to configure the SSIFilter
:)
The code below is conjecture - I didn't actually try it. I've been investigating whether it was possible to do what you're asking about, as a risk-assessment question. I'm interested - Did you actually pull this off? Has anyone?
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;
}
Upvotes: 0