我正在开发一个 Apache Sling WCMS 并使用 java 标签库来呈现一些数据。
我正在使用 IntelliJ IDEA 10.0
我用以下描述符和处理程序类定义了一个 jsp 标签库:
TLD 文件包含:
<?xml version="1.0" encoding="UTF-8"?>
<taglib version="2.1" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd">
<tlib-version>1.0</tlib-version>
<short-name>taglibdescriptor</short-name>
<uri>http://bob/taglibs</uri>
<tag>
<name>testTag</name>
<body-content>tagdependent</body-content>
<tag-class>org.bob.taglibs.test.TestTagHandler</tag-class>
</tag>
</taglib>
标记处理程序类:
package org.bob.taglibs.test;
import javax.servlet.jsp.tagext.TagSupport;
public class TestTagHandler extends TagSupport{
@Override
public int doStartTag(){
try {
pageContext.getOut().print("<h1>Helloooooooo</h1>");
} catch(Exception e) {
return SKIP_BODY;
}
return EVAL_BODY_INCLUDE;
}
}
我将标签库打包为BobTagLib.jar并使用 Sling Web 控制台将其部署为捆绑包。
我在部署在我的 Sling 存储库中的 jsp 页面中使用了这个标签库:
index.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="bob" uri="http://bob/taglibs" %>
<html>
<head><title>Simple jsp page</title></head>
<body>
<bob:testTag/>
</body>
</html>
(已编辑)清单.MF
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.3
Created-By: Bob Tech
Built-By: babak
Bundle-Version: 1.0.0
Bundle-Name: Bob Tag Library
Build-Jdk: jdk1.6.0_18
Bundle-Vendor: The Bob Technology Foundation
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.bob.taglibs
Bundle-Category: sling
调用页面会导致以下异常:
org.apache.sling.scripting.jsp.jasper.JasperException: /apps/TagTest/index.jsp(7,5) Unable to load tag handler class "org.bob.taglibs.test.TestTagHandler" for tag "bob:testTag"
...
谁能给我一个解决方案?
在此之前,我们会感谢任何帮助。