试过网上很多方案,无非是:
1.在Tomcat目录下的lib文件夹中或是Maven中引入加入jstl包和standard.jar
2把.tld文件放在WEB/INF下
可是添加了两个包之后问题还是没有解决,或是将tld文件放在web-INF下仍然存在这个问题。
原因:
找不到jstl类库中的.tld文件
解决办法:
关键是在tld文件中的uri不要使用绝对路径,如下。
<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 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>SimpleTagLibrary</short-name>
<!--此处不要使用绝地路径-->
<uri>puhao</uri>
<tag>
<description>my first tag</description>
<name>hello</name>
<tag-class>com.paul.tag.MyTag</tag-class>
<body-content>empty</body-content>
</tag>
</taglib>
使用:
<%@ taglib prefix="puhao" uri="puhao" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<puhao:hello/>
HelloWorld
</body>
</html>
完美解决。