Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing SiteMesh with RequestDispatcher's forward()
    text
    copied!<p>I'm attempting to integrate <a href="http://www.opensymphony.com/sitemesh/" rel="noreferrer">SiteMesh</a> into a legacy application using Tomcat 5 as my a container. I have a <code>main.jsp</code> that I'm decorating with a simple decorator.</p> <p>In <code>decorators.xml</code>, I've just got one decorator defined:</p> <pre><code>&lt;decorators defaultdir="/decorators"&gt; &lt;decorator name="layout-main" page="layout-main.jsp"&gt; &lt;pattern&gt;/jsp/main.jsp&lt;/pattern&gt; &lt;/decorator&gt; &lt;/decorators&gt; </code></pre> <p>This decorator works if I manually go to <code>http://example.com/my-webapp/jsp/main.jsp</code>. However, there are a few places where a servlet, instead of doing a redirect to a jsp, does a <a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/RequestDispatcher.html#forward(javax.servlet.ServletRequest,%20javax.servlet.ServletResponse)" rel="noreferrer">forward</a>:</p> <pre><code>getServletContext().getRequestDispatcher("/jsp/main.jsp").forward(request, response); </code></pre> <p>This means that the URL remains at something like <code>http://example.com/my-webapp/servlet/MyServlet</code> instead of the jsp file and is therefore not being decorated, I presume since it doesn't match the pattern in <code>decorators.xml</code>.</p> <p>I can't do a <code>&lt;pattern&gt;/*&lt;/pattern&gt;</code> because there are other jsps that do not need to be decorated by <code>layout-main.jsp</code>. I can't do a <code>&lt;pattern&gt;/servlet/MyServlet*&lt;/pattern&gt;</code> because <code>MyServlet</code> may forward to <code>main.jsp</code> sometimes and perhaps <code>error.jsp</code> at other times.</p> <p>Is there a way to work around this without expansive changes to how the servlets work? Since it's a legacy app I don't have as much freedom to change things, so I'm hoping for something configuration-wise that will fix this.</p> <p>SiteMesh's documentation really isn't that great. I've been working mostly off the example application that comes with the distribution. I really like SiteMesh, and am hoping I can get it to work in this case.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload