<taglib>标签在web.xml文件中报错解决方法

文章引用ITEYE网站博主jeelee的文章

配置web.xml文件时,taglib标签报错,但不会影响程序的运行,web.xml 如下:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app id="WebApp_ID" version="2.4" 
    xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> 
    <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 '{"http://java.sun.com/xml/ns/j2ee":description, "http://java.sun.com/xml/ns/j2ee":display-name, "http://java.sun.com/xml/ns/j2ee":icon, "http://java.sun.com/xml/ns/j2ee":distributable, "http://java.sun.com/xml/ns/j2ee":context-param, "http://java.sun.com/xml/ns/j2ee":filter, "http://java.sun.com/xml/ns/j2ee":filter-mapping, "http://java.sun.com/xml/ns/j2ee":listener, "http://java.sun.com/xml/ns/j2ee":servlet, "http://java.sun.com/xml/ns/j2ee":servlet-mapping, "http://java.sun.com/xml/ns/j2ee":session-config, "http://java.sun.com/xml/ns/j2ee":mime-mapping, "http://java.sun.com/xml/ns/j2ee":welcome-file-list, "http://java.sun.com/xml/ns/j2ee":error-page, "http://java.sun.com/xml/ns/j2ee":jsp-config, "http://java.sun.com/xml/ns/j2ee":security-constraint, "http://java.sun.com/xml/ns/j2ee":login-config, "http://java.sun.com/xml/ns/j2ee":security-role, "http://java.sun.com/xml/ns/j2ee":env-entry, "http://java.sun.com/xml/ns/j2ee":ejb-ref, "http://java.sun.com/xml/ns/j2ee":ejb-local-ref, "http://java.sun.com/xml/ns/j2ee":service-ref, "http://java.sun.com/xml/ns/j2ee":resource-ref, "http://java.sun.com/xml/ns/j2ee":resource-env-ref, "http://java.sun.com/xml/ns/j2ee":message-destination-ref, "http://java.sun.com/xml/ns/j2ee":message-destination, "http://java.sun.com/xml/ns/j2ee":locale-encoding-mapping-list}' is expected. 

解决方法有两个:

1、把

<web-app id="WebApp_ID" version="2.4" 
    xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

这句改成

<web-app > 

解 释:在jsp2.0中,且2.4版的DTD验证中,初步估计是由于eclipse在部署时,未对web.xml进行一些校验,而jbuilder则进行了 校验,并除非不合法的描述符,而taglib描述符,正确写法是放到描述符 中。

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。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个简单的jsp页面代码,实现了机票选择和购买功能: ```jsp <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>机票购买</title> </head> <body> <h1>机票选择</h1> <form action="buyTicket" method="post"> <table> <thead> <tr> <th>机票编号</th> <th>起飞时间</th> <th>到达时间</th> <th>起飞地点</th> <th>到达地点</th> <th>价格</th> <th>选择</th> </tr> </thead> <tbody> <c:forEach var="ticket" items="${ticketList}"> <tr> <td>${ticket.ticketId}</td> <td>${ticket.departureTime}</td> <td>${ticket.arrivalTime}</td> <td>${ticket.departurePlace}</td> <td>${ticket.arrivalPlace}</td> <td>${ticket.price}</td> <td><input type="checkbox" name="selectedTickets" value="${ticket.ticketId}"></td> </tr> </c:forEach> </tbody> </table> <input type="submit" value="购买"> </form> </body> </html> ``` 在上面的代码,使用了JSTL标签库的forEach标签遍历从后台传递过来的机票信息列表,然后使用HTML表格元素将机票信息以表格的形式展示出来。在每一行机票信息的最后一列,添加了一个复选框元素,name属性设置为“selectedTickets”,value属性设置为机票的唯一编号。当用户选择机票时,选复选框,表单提交时,后台程序就可以根据“selectedTickets”参数读取到用户选择的机票信息。 在表格的下方,添加了一个提交按钮,当用户选择完机票后,点击此按钮,提交表单,跳转到后台程序进行机票购买操作。 希望这段代码能对你有所帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值