展开全部
tld定义格式32313133353236313431303231363533e78988e69d8331333361323566
[java] view plain copy print?
/p>
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
定义Tag对应类
此类必须重写doStartTag以及doEndTag方法
[java] view plain copy print?
/**
*
*/
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;
}
}
在web.xml中加入taglib对应文件配置
如:
[java] view plain copy print?
http://mytag.sf.net
/WEB-INF/mytag.tld
这样就表示了http://mytag.sf.net对应WEB-INF/mytag.tld文件
在Jsp页面中引用
如:
在Jsp页面中使用
示例:
定义myTag.tld标签文件
[java] view plain copy print?
/p>
"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
定义标签类
[java] view plain copy print?
/**
*
*/
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添加配置
[java] view plain copy print?
http://mytag.sf.net
/WEB-INF/mytag.tld
测试页面
[java] view plain copy print?
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
My JSP 'tagtldDemo.jsp' starting pageThis is my JSP page.
本回答被提问者采纳
已赞过
已踩过<
你对这个回答的评价是?
评论
收起