在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>(應該是這樣,我個人的猜測)}