struts2之整合sitemesh(关于过滤一些不使用模板文件的注意事项) ---------
我们在用struts2与sitemesh整合时,我们可能会排除一些文件不使用模板。如例:
<?xml version="1.0" encoding="GBK"?> <decorators defaultdir="/decorators"> <!-- 在excludes元素下指定的页面将不会由sitemesh来装饰 --> <excludes> <pattern>/exclude.jsp</pattern> <pattern>/exclude/*</pattern> </excludes> <!-- 创建一个名为main的装饰器,该装饰器页面为main.jsp,用于装饰pattern指定的URL的所有页面 --> <decorator name="main" page="main.jsp"> <pattern>/*</pattern> </decorator> <!-- 定义一个装饰器,但该装饰器默认不装饰任何页面 --> <decorator name="panel" page="panel.jsp"/> </decorators>
我们在上例中,使用:
<excludes> <pattern>/exclude.jsp</pattern> <pattern>/exclude/*</pattern> </excludes>
排除了/exclude.jsp与/exclude/*下的所有文件。如果我们使用Action进行页面调度转向时,如果到达的页面是/exclude.jsp或者在/exclude/*之下,该页面还是会被套上模板。
所以我们可以这样排除:
<excludes> <pattern>/exclude.jsp</pattern> <pattern>/exclude/*</pattern> <pattern>xxxx.do</pattern> <pattern>/exclude/xxx.do</pattern> </excludes>
也就是我们可以对Action进行过滤。不仅仅是jsp文件。