展开全部
tld定义e5a48de588b63231313335323631343130323136353331333361323030格式
taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
1.0
1.2
Cms Tag
A simple appbase tag library
page
com.cms.common.tag.PageTag
empty
cmsform
true
true
2、定义Tag对应类
此类必须重写doStartTag以及doEndTag方法/**
*
*/
package com.cms.common.tag;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
/**
* @author louisliao
*
*/
public class DemoViewTag extends TagSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
private String cmsform = "";
public String getCmsForm() {
return cmsform ;
}
public void setCmsForm(String cmsform ) {
this.cmsform = cmsform ;
}
/**
*
*/
public DemoViewTag() {
// TODO Auto-generated constructor stub
}
public int doStartTag()
{
return super.SKIP_BODY;
}
public int doEndTag() throws JspException
{
JspWriter writer=pageContext.getOut();
try {
writer.print("这是我的标签示例
"+"cmsform :"+this.cmsform);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return super.EVAL_PAGE;
}
}
3、在web.xml中加入taglib对应文件配置 如:
http://mytag.sf.net
/WEB-INF/mytag.tld
示例:
定义myTag.tld标签文件<?xml version="1.0" encoding="utf-8"?>
taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
1.0
1.1
MyJSPTag Library
http://mytag.sf.net
我的示例标签库
demo.Viewport
com.myapp.web.tag.DemoViewTag
JSP
demo.Viewport标签
northTitle
true
true
westTitle
true
true
定义标签类/**
*
*/
package com.myapp.web.tag;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
/**
* @author louisliao
*
*/
public class DemoViewTag extends TagSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
private String northTitle = "";
private String westTitle = "";
public String getNorthTitle() {
return northTitle;
}
public void setNorthTitle(String northTitle) {
this.northTitle = northTitle;
}
public String getWestTitle() {
return westTitle;
}
public void setWestTitle(String westTitle) {
this.westTitle = westTitle;
}
/**
*
*/
public DemoViewTag() {
// TODO Auto-generated constructor stub
}
public int doStartTag()
{
return super.SKIP_BODY;
}
public int doEndTag() throws JspException
{
JspWriter writer=pageContext.getOut();
try {
writer.print("这是我的标签示例
westTitle:"+this.westTitle+"
northTitle:"+this.northTitle);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return super.EVAL_PAGE;
}
}
web.xml添加配置
http://mytag.sf.net
/WEB-INF/mytag.tld
测试页面
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
">
My JSP 'tagtldDemo.jsp' starting pageThis is my JSP page.