我想在我的jsp文档文件中使用这样的东西:
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
Run Code Online (Sandbox Code Playgroud)
但是,在我看过的所有30多个示例中,每个人都使用简单的jsp语法,而不是jsp文档语法.像这样的东西:
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:fmt="http://java.sun.com/jsp/jstl/fmt"
xmlns:t="/WEB-INF/tags"
xmlns="http://www.w3.org/1999/xhtml"
version="2.0">
Run Code Online (Sandbox Code Playgroud)
根本行不通.页面上看不到驻留在/ WEB-INF /标签中的所有标记文件.只有我定义了一个tld文件,并列出了那里的所有标签,才能在页面上访问它们.是否可以避免tld声明并仍在jsp文档页面中使用标记文件?
小智 6
您需要在xmlns属性中添加前缀"urn:jsptagdir:".在你的情况下,
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:fmt="http://java.sun.com/jsp/jstl/fmt"
xmlns:t="urn:jsptagdir:/WEB-INF/tags"
xmlns="http://www.w3.org/1999/xhtml"
version="2.0">
Run Code Online (Sandbox Code Playgroud)
您还可以使用前缀"urn:jsptld:"来指定TLD的位置.有关更多详细信息,请参阅http://docs.oracle.com/javaee/1.4/tutorial/doc/JSPX3.html中的 "声明标记库"一节.
1在WEB-INF /目录中创建标签目录
2创建sample.tag文件,其中您的标记将是:
<%@ attribute name="exampleAttribute" required="true" type="java.lang.String" description="Example attribute" %>
<c:out value="${exampleAttribute}">
Run Code Online (Sandbox Code Playgroud)
3在jsp中声明要使用它的标记库:
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
Run Code Online (Sandbox Code Playgroud)
4使用它:
<tags:sample exampleAttribute="Hello from custom tag!"/>
Run Code Online (Sandbox Code Playgroud)
而且我认为您应该拥有Web应用程序2.5的版本.只考虑那个版本支持JSP 2.0(在web.xml中检查).
| 归档时间: |
|
| 查看次数: |
9308 次 |
| 最近记录: |