<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/j2ee/dtd/web-jsptaglibrary_1_2.dtd">
如果用以上做开头编译后会告诉你找不到外部文件http file://java.sun.com/j2ee/dtd/
web-jsptaglibrary_1_2.dtd,我想可能是上述URI用于企业版里,而我没有安装j2ee所造 成的。如果我说的不对请大虾们指正,我的E-mail:flyhelleryuanwei@yahoo.com.cn。
******************************************************************************
有了以上的基础我们可以向刚刚建立的文档中添加内容了。
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>1.2</jsp-version>
<uri>heller.database</uri>
<description>
A simple tab library for the database
</description>
... ...
</taglib>
... ...
<tag>
<name>simtag</name>
<tag-class> temp.simtag </tag-class>
<body-content> JSP </body-content>
</tag>
... ...
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>1.2</jsp-version>
<uri>heller.database</uri>
<description>
A simple tab library for the database
</description>
<tag>
<name>simtag</name>
<tag-class> temp.simtag </tag-class>
<body-content> JSP </body-content>
</tag>
</taglib>
package temp;
import javax.servlet.jsp.tagext.*;
import javax.servlet.jsp.*;
public class simtag extends TagSupport {
private static int guestNum = 0;
public int doStartTag() throws JspException {
try {
guestNum++;
pageContext.getOut().println("Hello!");
pageContext.getOut().println("You are the " + guestNum + "st guset!");
} catch (Exception ex) {
throw new JspTagException("SimpleTag: " +
ex.getMessage());
}
return SKIP_BODY;
}
public int doEndTag() {
return EVAL_PAGE;
}
}
<?xml version="1.0" encoding="ISO-8859-1"?>code 6
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<taglib>
<taglib-uri>/database.tld</taglib-uri>
<taglib-location>
/WEB-INF/database.tld
</taglib-location>
</taglib>
</web-app>
<%@ taglib uri="/database.tld" prefix="database" %>code 7
<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="java.io.*" %>
<html>
<head>
<title>
hello
</title>
</head>
<body bgcolor="#00ffff">
<h1>
<database:simtag>
</database:simtag>
</h1>
</body>
</html>
home
jsp
hello.jsp
WEB-INF
classes
temp
simtag.class
web.xml
database.tld
(出处:http://www.VeVb.com)
新闻热点
疑难解答