Custom Tags tutorial

原创 2006年06月21日 17:35:00

It's very simple and not full. The simple process is:

1. Write class: the class usually inherit (extend) TagSupport (or some other). The functions below are useful:

public int doEndTag()
             throws JspException
public int doStartTag()
               throws JspException
 
the example is below:
public class DemoTag extends TagSupport {
 
 private String name = "oriName";
 public int doStartTag() throws JspException {
  //HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
  JspWriter out = pageContext.getOut();
  try {
   out.println("Tags Entered...........");
   out.println("Name is " + name + "..............");
  } catch (IOException e) {
      e.printStackTrace();
  }
 
  return SKIP_BODY;
 }
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
}

2. define tld (tag library define) file, below is one example, the header of the file is important:

<?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>site-utils</short-name>
  <tag>
      <name>demoTag</name>
      <tag-class>com.tcs.tags.DemoTag</tag-class>
      <body-content>empty</body-content>
      <attribute>
      <name>name</name>
      </attribute>
    </tag>
</taglib>

On above, the <attribut> is the point deciding if the tag has parameters.

3. Use the tag in JSP:

3.1 declear the taglib, like:

<%@ taglib uri="/WEB-INF/myTagLib.tld" prefix="myTag" %>

3.2 use:

<myTag:demoTag name="changedName"/>

 

4. OK :)

 

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

Custom-Tags-Ajax.pdf

  • 2008-08-02 13:29
  • 579KB
  • 下载

Custom-Tags-Advanced.pdf

  • 2008-08-02 13:30
  • 291KB
  • 下载

JSP - Custom Tags

A custom tag is a user-defined JSP language element. When a JSP page containing a custom tag is tran...

\\Custom-Tags-Basics.pdf

  • 2008-08-02 13:28
  • 413KB
  • 下载

JSP Custom Tags Example

<%@ include file=”relativeURI”%> 可以叫作静态include(静态包含),是jsp指令中的一种,(JSP指令控制JSP编译器如何去生成servlet。 <jsp:in...

JSTL简单教程--JSTL核心标签(JSTL Tutorial with Examples – JSTL Core Tags)

JSP Standard Tag Library (JSTL)是一个标准的标签库用来控制jsp的行为、迭代和控制表现、国际化以及sql等。 JSTL是javaEE的一部分并被绝大部分servlet容...

UIGestureRecognizer Tutorial: Creating Custom Recognizers

来源:点击打开链接 Custom gesture recognizers delight users by making apps feel unique and alive. If basic ...

The Cairo graphics tutorial -------Custom GTK widget

In this part of the Cairo graphics tutorial, we will create a custom GTK widget, where we will use t...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)