Choosing an appropriate url pattern for Sitemesh to exclude my servlet from its decorators?

cafe picture cafe · Sep 13, 2010 · Viewed 8.1k times · Source

I configured my Spring web app with a servlet to serve images at the URL:

/imgsrv?imgid=12345

I also have Sitemesh installed and now when I call this image servlet, I get a decorator exception related to this servlet, which does not need a decorator applied to it.

According to the Sitemesh docs, you can exclude certain URLs from having a decorator applied to them but the syntax is not clear to me.

Which of the following patterns would seem to be most correct to exclude the URL above from being "decorated":

<decorators defaultdir="/WEB-INF/view/decorators">
    <excludes>
        <pattern>/imgsrv*</pattern>
        <pattern>/imgsrv/*</pattern>
        <pattern>/imgsrv**</pattern>
        <pattern>/imgsrv/**</pattern>
        <pattern>/imgsrv*.*</pattern>
        <pattern>/imgsrv/*.*</pattern>
    </excludes>
    <decorator name="main" page="main.jsp">
        <pattern>/*</pattern>
    </decorator>
</decorators>

Answer

Tomas Narros picture Tomas Narros · Sep 13, 2010

I think that this would be enough:

<decorators defaultdir="/WEB-INF/view/decorators">
    <excludes>
        <pattern>/imgsrv</pattern>
    </excludes>
    <decorator name="main" page="main.jsp">
        <pattern>/*</pattern>
    </decorator>
</decorators>

You are mapping directly to a known servlet path. You don't need wildcard to handle the parameters ( as in ?imgid=12345 ).