81,092
社区成员
发帖
与我相关
我的任务
分享
package mytag;
import java.io.IOException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.TagSupport;
public class Helloworld extends TagSupport {
public int doEndTag()throws JspTagException
{
try {
pageContext.getOut().write("Helloworld");
} catch (IOException e) {
// TODO Auto-generated catch block
throw new JspTagException("错误");
}
return EVAL_PAGE;
}
}
<?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>
<short-name>mytag</short-name>
<uri>http://www.tag.com/mytag</uri>
<tag>
<name>Helloworld</name>
<tag-class>mytag.Helloworld</tag-class>
<body-content>empty</body-content>
</tag>
</taglib>
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
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-app_2_5.xsd">
<taglib>
<taglib-uri>http://www.tag.com/mytag</taglib-uri>
<taglib-location>/WEB-INF/HelloworldTag.tld</taglib-location>
</taglib>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://www.tag.com/mytag"prefix="mytag" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
<mytag:Helloworld/>
</body>
</html>
<taglib>
<tlib-version>1.0 </tlib-version>
<jsp-version>1.2 </jsp-version>
<short-name>mytag </short-name>
<!--这里的uri基本重复,不起作用,可以不用写
<uri>http://www.tag.com/mytag </uri>
-->
<tag>
<name>Helloworld </name>
<tag-class>mytag.Helloworld </tag-class>
<body-content>empty </body-content>
</tag>
</taglib>
<!--在前面加上jsp-config标签队来配置就不会出警告了 -->
<jsp-config>
<taglib>
<taglib-uri>http://www.tag.com/mytag </taglib-uri>
<taglib-location>/WEB-INF/HelloworldTag.tld </taglib-location>
</taglib>
</jsp-config>