web.xml与tld文件的关系:
由web.xml指示tld文件的实际位置和引用名称.
<jsp-config>
<taglib>
<taglib-uri>以什么样的名称引用</taglib-uri>
<taglib-location>在工程中的位置</taglib-location>
</taglib>
</jsp-config>在jsp界面中一般用引用名称.
你可以对你下你的tld路径是否正确,jsp中的引用和web.xml中<taglib-uri>以什么样的名称引用</taglib-uri>是否一致.如jsp文件中
<%@ taglib uri="/ww" prefix="ww"%>
web.xml
<jsp-config>
<taglib>
<taglib-uri>/ww</taglib-uri>
<taglib-location>在工程中的位置</taglib-location>
</taglib>
</jsp-config>
由web.xml指示tld文件的实际位置和引用名称.
<jsp-config>
<taglib>
<taglib-uri>以什么样的名称引用</taglib-uri>
<taglib-location>在工程中的位置</taglib-location>
</taglib>
</jsp-config>在jsp界面中一般用引用名称.
你可以对你下你的tld路径是否正确,jsp中的引用和web.xml中<taglib-uri>以什么样的名称引用</taglib-uri>是否一致.如jsp文件中
<%@ taglib uri="/ww" prefix="ww"%>
web.xml
<jsp-config>
<taglib>
<taglib-uri>/ww</taglib-uri>
<taglib-location>在工程中的位置</taglib-location>
</taglib>
</jsp-config>
prefix="ww"指定你用这个标签的前缀.
如---- ww:property
现在那个tld文件中提示不能找到 "<taglib>"标签,这个该怎样解决呢?
web.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<jsp-config>
<taglib>
<taglib-uri>/demotag</taglib-uri>
<taglib-location>/WEB-INF/tlds/mytag.tld</taglib-location>
</taglib>
</jsp-config></web-app>mytag.tld文件:
<?xml version="1.0" encoding="ISO-8859-1" ?><taglib 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 web-jsptaglibrary_2_0.xsd"
version="2.0">
<description>A tag library exercising SimpleTag handlers.</description>
<tlib-version>1.0</tlib-version> <short-name>examples</short-name>
<uri>/demotag</uri>
<description>
A simple tab library for the examples
</description> <tag>
<name>hello</name>
<tag-class>com.jspdev.ch14.HelloTag</tag-class>
<body-content>empty</body-content>
<description>
Simple hello world examples.
Takes no attribute,and simply generates HTML
</description>
</tag>
</taglib>现在<taglib>标签旁有一个红色的小错号,提示:
cannot find the declaration of element 'taglib'
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd"
version="2.0">
<description>A tag library exercising SimpleTag handlers.</description>
<tlib-version>1.0</tlib-version>改成<taglib>试试
在你的jsp引用的位置写 .tld得确切位置就可以减少错误的发生了<%@ taglib uri="/WEB-INF/tlds/mytag.tld" prefix="ww"%>
prefix="ww"指定你用这个标签的前缀.
property 是你的.Tld文件给你的类起的名字
如---- ww:property
prefix="ww"指定你用这个标签的前缀.
property 是你的.Tld文件给你的类起的名字
如---- ww:propertyjsp页面是这样写的么?常犯的错误是丢掉了"/demotag"中的"/"
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd" >
有没有导入4个jar包啊,使用taglib标签,需要导包的