2010-09-23 33 views
22

Tôi có web.xml nàyTại sao <taglib> đem lại cho tôi một vấn đề trong web.xml của tôi

<?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"> 
    <display-name>jsp-tags</display-name> 
    <taglib> 
     <taglib-uri>mytags</taglib-uri> 
     <taglib-location>/WEB-INF/mytaglib.tld</taglib-location> 
    </taglib> 
    <welcome-file-list> 
    <welcome-file>index.html</welcome-file> 
    <welcome-file>index.htm</welcome-file> 
    <welcome-file>index.jsp</welcome-file> 
    <welcome-file>default.html</welcome-file> 
    <welcome-file>default.htm</welcome-file> 
    <welcome-file>default.jsp</welcome-file> 
    </welcome-file-list> 
</web-app> 

được tô đậm và lỗi IDE cho là: "Nội dung không hợp lệ đã được tìm thấy bắt đầu với yếu tố ...

gì hơn làm tôi cần phải làm

+0

Bạn còn cần phải làm gì hơn? Bạn cần chấp nhận câu trả lời của @ Jaydeep. :-P –

Trả lời

45

Sử dụng ký hiệu này:

<jsp-config> 
     <taglib> 
       <taglib-uri>mytags</taglib-uri> 
       <taglib-location>/WEB-INF/jsp/mytaglib.tld</taglib-location> 
     </taglib> 
</jsp-config> 

Nhưng tôi đề nghị để đọc link này. Hướng dẫn này sẽ cung cấp cho bạn ý tưởng cách tránh tuyên bố thẻ taglib trong web.xml trong trường hợp của JSP 2.0

+0

Thanx rất nhiều. Nó làm việc cho tôi !!! –

+0

Làm việc cho tôi! cảm ơn Jaydeep. –

6

trong XSD được tham chiếu trong XML của bạn, nó khẳng định rằng cho loại hình phức tạp web appType bạn chỉ có thể có một lựa chọn không nhiều các yếu tố sau:

<xsd:choice minOccurs="0" maxOccurs="unbounded"> 
    <xsd:group ref="javaee:descriptionGroup"/> 
    <xsd:element name="distributable" 
type="javaee:emptyType"/> 
    <xsd:element name="context-param" 
type="javaee:param-valueType"> 

    </xsd:element> 
    <xsd:element name="filter" 
type="javaee:filterType"/> 
    <xsd:element name="filter-mapping" 
type="javaee:filter-mappingType"/> 
    <xsd:element name="listener" 
type="javaee:listenerType"/> 
    <xsd:element name="servlet" 
type="javaee:servletType"/> 
    <xsd:element name="servlet-mapping" 
type="javaee:servlet-mappingType"/> 
    <xsd:element name="session-config" 
type="javaee:session-configType"/> 
    <xsd:element name="mime-mapping" 
type="javaee:mime-mappingType"/> 
    <xsd:element name="welcome-file-list" 
type="javaee:welcome-file-listType"/> 
    <xsd:element name="error-page" 
type="javaee:error-pageType"/> 
    <xsd:element name="jsp-config" 
type="javaee:jsp-configType"/> 
    <xsd:element name="security-constraint" 
type="javaee:security-constraintType"/> 
    <xsd:element name="login-config" 
type="javaee:login-configType"/> 
    <xsd:element name="security-role" 
type="javaee:security-roleType"/> 
    <xsd:group ref="javaee:jndiEnvironmentRefsGroup"/> 
    <xsd:element name="message-destination" 
type="javaee:message-destinationType"/> 
    <xsd:element name="locale-encoding-mapping-list" 
type="javaee:locale-encoding-mapping-listType"/> 
</xsd:choice> 

Yếu tố taglib không được tham chiếu trong XSD.

Từ đọc this link có vẻ như bạn không cần phải khai báo thẻ taglib trong tài liệu ứng dụng web. Chỉ cần có thuộc tính version = "2.5" có nghĩa là bạn có thể tham chiếu các thẻ trong JSP của mình.

0

Nếu taglib nằm bên trong phụ thuộc mút maven, chỉ cần thiết lập phạm vi biên dịch.

<dependency> 
    <groupId>org.apache.struts</groupId> 
    <artifactId>struts-taglib</artifactId> 
    <version>1.3.10</version> 
    <scope>compile</scope> 
</dependency> 
Các vấn đề liên quan