Sitemesh 3 has this as a bug in their GitHub page:
I've found 2 ways around it so far. Rename *.html files to *.jsp. This will make Tomcat use the same output buffer, and the pages will load correctly. I tested tried that out, and it worked fine. I can't use it right now though, I have way too many HTML files, and links(internal and external) etc.
The way I ended up solving this was to create a HttpServlet and filter all calls to *.html into it. Here's my code:
web.xml
<servlet>
<servlet-name>html</servlet-name>
<servlet-class>com.holstein.servlets.HTMLServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>html</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
HTMLServlet.java
public class HTMLServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException, ServletException {
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
BufferedReader bw = new BufferedReader(new FileReader(req.getRequestURI().toString()));
while(bw.ready())
{
out.println(bw.readLine()); //this is an old school way to output the data.
// I think it's way out of form, and deprecated at this point
}
}
}
This is by no means a pretty fix, but it's functional. I need to do a major rewrite of our site and possibly get rid of Sitemesh for Tiles or something else. The other thing would be to get a pull on Sitemesh 3, and fix the the bug there (or wait for someone to do it). This assumes there isn't a version out there with the fix in it.
I'm using Maven from
mvnrepository.com to control all my dependencies. I have the latest Sitemesh from there, but I think it is a little stale.