使用SiteMesh和Jquery的一些问题

在项目中使用了SiteMesh框架修饰jsp页面,同时使用了jquery的页面要注意以下一些问题:
1、必须将js文件放在</head>之前或者<body></body>之间,如果放在</head>和<body>之间的话,被修饰的jsp页面将不会引人这些js,导致不能执行脚本。
2、sitemesh的修饰
     它通过过滤器(filter)来拦截页面访问,并根据被访问页面的URL找到合适的装饰模板,然后提取被访问页面的内容,放到装饰模板中合适的位置,最终将装饰后的页面发送给客户端。因此如果被修饰页面用到了jquery,就要在自己的页面中加入jquery.js文件,不要写在sitemesh模板页里面,否则很可能出现"Jquery un defined"异常。
3、如果被装饰的页面的body有onload方法,则不会执行该onload方法,因为只是加入body内部的内容。可以使用jquery的ready方法替代onload方法。

     可以通过 sitemesh的 配置解决。

    备注:

http://czy-sysu.iteye.com/blog/646665

4.   一定在要decorators.xml文件中 排除不需要装饰的文件

    <excludes>
     <pattern>*/ajax/*</pattern>
     <pattern>*.js</pattern>
     <pattern>*.css</pattern>
     <pattern>*.html</pattern>     
     <pattern>*.jws</pattern>
     <pattern>/test/*</pattern>
    </excludes>

http://coos.group.iteye.com/group/wiki/1802-action-to-exclude-sitemesh-decoration-tips

sitemesh装饰模式的强大就不用说了,但使用过程中遇到的最郁闷的莫过于排除装饰action的困扰了,例如使用某个ajax请求要求返回不装饰的数据,但sitemesh却死活给你装饰了,以前用了个小技巧绕过了sitemesh的装饰--在返回的头部声明为xml类型:ServletActionContext.getResponse().setContentType("text/xml;charset=utf-8");

看了文档知道sitemesh默认装饰所有text/html的页面的,要装饰其他类型的页面还得自己配置。

但是总觉得这样很麻烦,况且有些页面是对外公开的api页面,只需要显示内容给其他iframe嵌入,这个时候如何排除呢?

在excludes里面排除的却总是不起作用!

经过查阅文档和不断的实践终于发现无法排除的原因了,原来排除的是相对于url目录层次的,而非文件所在的目录!

<!-- 在excludes元素下指定的页面将不会由SiteMesh来装饰 -->
 <excludes>
  <pattern>/index.jsp</pattern>
  <pattern>/scripts/*.*</pattern>
  <pattern>/htmleditor/*.*</pattern>
  <pattern>/chart/*.*</pattern>//排除chart目录下的所有action请求
  <pattern>/flash/*.*</pattern>
  <pattern>/other/*.*</pattern>
  <pattern>/remote_requst.action*</pattern>//排除根目录下的remote_requst.action包括带参数的请求,如果action后面不带*则只能排除不带参数的请求
 </excludes>

<decorator name="global" page="global.ftl">
  <pattern>*.action</pattern>
 </decorator>
 <decorator name="editor" page="blog.ftl" webapp="/editor/">
  <pattern>/editor/*.action</pattern>
 </decorator>
 
 <decorator name="browser" page="blog.ftl" webapp="/browser/">
  <pattern>/browser/*.action</pattern>
 </decorator>
 
 <decorator name="admin" page="admin.ftl" webapp="/admin/">
  <pattern>/admin/*.action</pattern>
 </decorator>

猜你喜欢

转载自fhqllt.iteye.com/blog/1150736