ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button
  Designing JSP Custom Tag Libraries
Subject:   corrected files (including web.xml)
Date:   2003-02-14 09:59:11
From:   anonymous2

<%@ taglib uri="/WEB-INF/oreillySample.tld" prefix="sample" %>
<title>Your Standard Hello World Demo</title>
<body bgcolor="#ffffff">
<hr />
<sample:hello name="Sue"/>
<hr />


package com.ml.gmi.edsi.ipro.client.action.testClasses;

import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
* This is a simple tag example to show how content is added to the
* output stream when a tag is encountered in a JSP page.
public class Hello extends TagSupport {
private String name=null;
* Getter/Setter for the attribute name as defined in the tld file
* for this tag
public void setName(String value){
name = value;

public String getName(){

* doStartTag is called by the JSP container when the tag is encountered
public int doStartTag() {
try {
JspWriter out = pageContext.getOut();
out.println("<table border=1>");
if (name != null)
out.println("<tr><td> Hello " + name + " </td></tr>");
out.println("<tr><td> Hello World </td></tr>");
} catch (Exception ex) {
throw new Error("All is not well in the world.");
// Must return SKIP_BODY because we are not supporting a body for this
// tag.
return SKIP_BODY;
* doEndTag is called by the JSP container when the tag is closed
public int doEndTag(){
try {
JspWriter out = pageContext.getOut();
} catch (Exception ex){
throw new Error("All is not well in the world.");
return EVAL_PAGE;


<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"

<info>OReilly Sample Tag library</info>


<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"


<!-- Action Servlet Configuration -->

<!-- Action Servlet Mapping -->