java tld文件配置_如何在JavaWeb程序中使用tld文件

tld定义格式

1.0

1.2

Cms Tag

A simple appbase tag library

page

com.cms.common.tag.PageTag

empty

cmsform

true

true

定义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;

}

}

在web.xml中加入taglib对应文件配置

如:

http://mytag.sf.net

/WEB-INF/mytag.tld

这样就表示了http://mytag.sf.net对应WEB-INF/mytag.tld文件

在Jsp页面中引用

如:

在Jsp页面中使用

示例:

定义myTag.tld标签文件

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

测试页面

My JSP 'tagtldDemo.jsp' starting page

This is my JSP page.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值