Jsp:taglib实现

2020-11-26 19:39

阅读:804

标签:style   blog   class   code   java   tar   

web应用的结构:

          web.xml

          classes   diegoyun OutputTag.class

    WEB-INF  src    diegoyun OutputTag.java

mytag       tlds   diego.tld

    tag.jsp

细节:

web.xml:

soscw.com,搜素材
1 xml version="1.0" encoding="GBK"?>
2 web-app xmlns="http://java.sun.com/xml/ns/javaee"
3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
5     http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
6     version="3.0">
7 web-app>
soscw.com,搜素材

OutputTag.java:

soscw.com,搜素材
 1 package diegoyun;
 2 import javax.servlet.jsp.JspException;
 3 import javax.servlet.jsp.JspWriter;
 4 import javax.servlet.jsp.tagext.TagSupport;
 5 
 6 public class OutputTag extends TagSupport
 7 {
 8  private String name=null; 
 9  public void setName(String name)
10  {
11   this.name = name;
12  }
13  
14  public int doStartTag() throws JspException{
15   try
16   {
17    JspWriter out = pageContext.getOut();
18    out.print("Hello! " + name);
19   }
20   catch (Exception e)
21   {   
22    throw new JspException(e);
23   }
24   return EVAL_PAGE;
25  }
26 }
soscw.com,搜素材

diego.tld:

soscw.com,搜素材
 1 xml version="1.0" encoding="GBK" ?>
 2 
 3 taglib xmlns="http://java.sun.com/xml/ns/j2ee"
 4     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 5     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd"
 6     version="2.0">
 7  tlib-version>1.0tlib-version>
 8  short-name>diegoshort-name>  
 9  
10  tag>
11   name>outname>
12   tag-class>diegoyun.OutputTagtag-class>
13   body-content>emptybody-content>
14   attribute>
15    name>namename>
16    required>falserequired>
17    rtexprvalue>falsertexprvalue>
18   attribute>
19  tag>
20 taglib>
soscw.com,搜素材

tag.jsp:

soscw.com,搜素材
 1 %@ page contentType="text/html; charset=GBK" language="java" errorPage="" %>
 2 
 3 %@ taglib uri="/WEB-INF/tlds/diego.tld" prefix="diego"%>
 4 DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 5     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 6 html xmlns="http://www.w3.org/1999/xhtml">
 7 body>
 8 Test Tag:
 9 diego:out name="diegoyun"/>
10 body>
11 html>
soscw.com,搜素材

 

Jsp:taglib实现,搜素材,soscw.com

Jsp:taglib实现

标签:style   blog   class   code   java   tar   

原文地址:http://www.cnblogs.com/wanghui390/p/3706319.html


评论


亲,登录后才可以留言!