在web.xml加入taglib

<taglib>

<taglib-uri>/WEB-INF/tiles.tld</taglib- uri>

<taglib-location>/WEB-INF/tiles.tld</taglib- location>

</taglib>

 始终会报错 这是使用版本的问题 如果是2.3版本是可以直接在<web-app>里面书写

 对于2.4(貌似是2.4及以后版本都是这样)的web-app,taglib标签的放置位置已经发生改变,要放在<jsp-config>标签下

<jsp-config>

<taglib>

<taglib-uri>/WEB-INF/tiles.tld</taglib-uri>

<taglib-location>/WEB-INF/tiles.tld</taglib-location>

</taglib>

 </jsp-config>即可。下面给出一个完整2.5版本书写方法:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <jsp-config>
       <taglib>
           <taglib-uri>/WEB-INF/tiles.tld</taglib-uri>
           <taglib-location>/WEB-INF/tiles.tld</taglib-location>
       </taglib>
  </jsp-config>  
</web-app>

其中,<taglib-location>/WEB-INF/tiles.tld</taglib-location>  就表明在你的项目WEB-INF下会有一个tld后缀的名为titles的文件。

         <taglib-uri>/WEB-INF/tiles.tld</taglib-uri>这里应填的内容是取的tiles.tld文件里的这段话<uri>/WEB-INF/tiles.tld</uri>

  那么这个tiles.tld文件是哪里来的呢    貌似可以自己编写  (当然我是不会的- -。)

  我这想用的是struts2里自带的标签 所以就完全复制struts2-core-2.1.8.1.jar/META-INF/sturts-tags.tld里面的内容到tiles.tld文件里。

  然后我们在JSP里写入<%@taglib  uri="/WEB-INF/tiles.tld"%> 这段话就可以用struts2自带的标签功能了。

  {注意这个prefix="s" 中的s也是取的tiles.tld文件里的这段话<short-name>s</short-name>(应该是这样,我个人的猜测)}

posted on 2011-11-30 13:27  你妹啊。  阅读(7881)  评论(0编辑  收藏  举报