1. 程式人生 > >web.xml中taglib標籤報錯問題解決方案

web.xml中taglib標籤報錯問題解決方案

<taglib>標籤在web.xml檔案中報錯解決方法
配置web.xml檔案時,taglib標籤報錯,但不會影響程式的執行,web.xml 如下:

< xml version="1.0" encoding="UTF-8" >
<web-app id="WebApp_ID" version="2.4"
    xmlns="" xmlns:xsi=""
    xsi:schemaLocation="">
    <display-name>testSitemesh</display-name>
    <filter>
        <filter-name>sitemesh</filter-name>

        <filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>sitemesh</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <taglib>
        <taglib-uri>sitemesh-decorator</taglib-uri>

        <taglib-location>/WEB-INF/sitemesh-decorator.tld</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>sitemesh-page</taglib-uri>
        <taglib-location>/WEB-INF/sitemesh-page.tld</taglib-location>
    </taglib>
    <welcome-file-list>

        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

其中的taglib標籤加入後,eclipse報錯,內容如下:

cvc-complex-type.2.4.a: Invalid content was found starting with element 'taglib'. One of '{"":description, "":display-name, "":icon, "":distributable, "":context-param, "":filter, "":filter-mapping, "":listener, "":servlet, "":servlet-mapping, "":session-config, "":mime-mapping, "":welcome-file-list, "":error-page, "":jsp-config, "":security-constraint, "":login-config, "":security-role, "":env-entry, "":ejb-ref, "":ejb-local-ref, "":service-ref, "":resource-ref, "":resource-env-ref, "":message-destination-ref, "":message-destination, "":locale-encoding-mapping-list}' is expected.

解決方法有兩個:

1、把<web-app id="WebApp_ID" version="2.4"
    xmlns="" xmlns:xsi=""
    xsi:schemaLocation="">

這句改成<web-app >

解 釋:在jsp2.0中,且2.4版的DTD驗證中,初步估計是由於eclipse在部署時,未對web.xml進行一些校驗,而jbuilder則進行了 校驗,併除非不合法的描述符,而taglib描述符,正確寫法是放到<jsp-config$amp;>amp;$lt;/jsp-config>描述符 中。

2、在taglib外面加個jsp-config標籤:

<jsp-config>
  <taglib>
    <taglib>
        <taglib-uri>sitemesh-decorator</taglib-uri>
        <taglib-location>/WEB-INF/sitemesh-decorator.tld</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>sitemesh-page</taglib-uri>
        <taglib-location>/WEB-INF/sitemesh-page.tld</taglib-location>
    </taglib>
</jsp-config>

<jsp-config>標籤使用詳解:
<jsp-config> 包括<taglib> 和<jsp-property-group> 兩個子元素。

其中<taglib>元素在JSP 1.2時就已經存在;而<jsp-property-group>是JSP 2.0 新增的元素。
<jsp-property-group>元素主要有八個子元素,它們分別為:
1.<description>:設定的說明;
2.<display-name>:設定名稱;
3.<url-pattern>:設定值所影響的範圍,如:/CH2 或 /*.jsp;
4.<el-ignored>:若為true,表示不支援EL 語法;
5.<scripting-invalid>:若為true,表示不支援<% scripting %>語法;
6.<page-encoding>:設定JSP 網頁的編碼;
7.<include-prelude>:設定JSP 網頁的擡頭,副檔名為.jspf;
8.<include-coda>:設定JSP 網頁的結尾,副檔名為.jspf。