Programming Tutorials Browser Tutorials Articles Struts Tutorials Hibernate Tutorials

  Tutorial: Using Taglib in JSP. A brief introduction to taglibs and taglibs programing.

Using Taglib in JSP. A brief introduction to taglibs and taglibs programing. JSP TAG LIBRARIES JSP Tag Libraries : JSP’s offer a unique feature of “Tag Libraries”. Simply put, these are custom defined JSP tags. They are basically meant for

Tutorial Details:

componentizing presentation level logic. They are very similar to beans except the fact that Beans are used to separate Business logic.
Every tag is mapped to a particular class file which is executed whenever the tag is encountered in an JSP file.
The general syntax :
<%@ taglib uri=“ - - - - - ” prefix = “ - - - ” %>
The parent of the tag is the JSP tag within which it is nested, if there isn’t one, its set to null.
There are two things to remember while using TAGLIB’s :
The Class file should be created and it should be deployed in the Servlet folder of the web server. The class file should implement the Tag and BodyTag interfaces.
The mapping of a particular tag to a particular class file should be done in the taglib.tld file.
The tag is then ready to be used in the JSP file !!
The taglib file forms the central description for the tag library :
This file is an XML document that defines the tag’s operation.
It maps the tag name on the page to the implementing class.
It defines inputs to the class.
It references the helper class that provides details of any output variables set by the tag class.
This Tag and Bodytag have some methods, these all methods are callback methods.
Tag methods: doStartTag()
doEndTag()
Body Tag : doAfterBody()
Let’s have small example to display Hello World :
1. First we write simple jsp file
<% @ taglib uri=”/taglib.tld” prefix=”nt” %>





2. It will look for file specified in uri attribute,that file will be


1.0
1.1
nt

Hello World
mytags.HelloWorld
empty


3. Next this will look for Helloworld .class file will be
Package mytags;
Import javax.servlet.jsp.*;
Import javax.servlet.jsp.tagtext.*;
Public class Helloworld implements Tag {
private PageContext pagecontext;
private Tag parent;
public int doStartTag() throws JSPException {
return SKIP_BODY;
}
public int doEndTag () throws JSPException {
try{
pageContext.getOut().write(“Hello World”);
} catch(java.io.Exception ex) {
throw new JSPException(“IO Exception”);
}
return EVAL_PAGE;
}
public void release (){}
public void setPageContext(pageContext p) {
pageContext=p;
}
public void setParent(Tag t) {
parent = t;
}
public void getParent() {
return parent;
}
}
Flow of programme:
Here in first .jsp file we are writing tag.But name and properties of this tag we are writing in .tld file. And whatever task that tag is going to perform is written in .class file which has been called by .tld file.
So by using taglib we can create our own defined tags.
Author: Hrishikesh Deshpande


 

Rate Tutorial:
http://www.roseindia.net/jsp/jsptaglibraries.shtml

Read Tutorial at: Click here to view the tutorial

Rate Tutorial:
Using Taglib in JSP. A brief introduction to taglibs and taglibs programing.

View Tutorial:
Using Taglib in JSP. A brief introduction to taglibs and taglibs programing.

Related Tutorials:

Encapsulate reusable functionality in JSP
This tutorial shows you how you can encapsulate the resuable functionality in JSP pages.
 
UI design with Tiles and Struts
UI design with Tiles and Struts
 
JSP Standard Tag Library eases Webpage development
JSP Standard Tag Library eases Webpage development
 
Call JavaBean methods from JSP
Call JavaBean methods from JSP 2.0 pages
 
welofunc performer
welofunc performer is a web load test tool to support quality assurance of J2EE web applications.
 
Creating EL-Aware Taglibs Using XDoclet
Creating EL-Aware Taglibs Using XDoclet When the JSP Tag Extensions (also known as taglibs) first came out, the only option to pass dynamic values as tag attributes was using Request Time (RT) expressions. With the advent of JSTL 1.0, another option ha
 
Using a JMS Provider with MDBs via the J2EE Connector Architecture
Using a JMS Provider with MDBs via the J2EE Connector Architecture In this article I will provide a brief introduction to MDB and the J2EE Connector Architecture (JCA), examining how MDBs can be deployed with the JCA 1.5 resource adapter to use a JMS pro
 
Introduction to Tag Unit
Getting Started For the purpose of this article, let's say that we would like to test the core taglib from the Jakarta Taglibs implementation of the JSTL, a taglib that many people will be aware of and have experience with. Assuming that you already have
 
Introduction to JSP
Introduction to JSP Introduction to JSP Java Server Pages or JSP for short is Sun's solution for developing dynamic web sites. JSP provide excellent server side scripting support for creating database driven web applications. JSP enable the
 
JavaServer Pages Technology - Documentation
Sun's tutorial for Java Server Pages that provide a good introduction to design web pages with JSP.
 
Jakarta Taglibs
This project is an open-source repository for JSP custom tag libraries and associated projects, such as TagLibraryValidator classes and extensions to page-creation tools to support tag libraries.
 
J2EE pathfinder: Implement JSP custom tags in five easy steps
JSP custom tags provide a standardized mechanism for separating presentation and business logic in a dynamic Web page, allowing page designers to focus on presentation while application developers code the back end. In this installment of J2EE pathfinder,
 
Encapsulate reusable functionality in JSP tags
JavaServer Pages (JSP) are a great mechanism for delivering dynamic Web-based content. JSP provides a set of predefined tags, but you can also define your own tag extensions that encapsulate common functionality.
 
Welcome to the Apache Struts Tutorial
This is the complete Struts Tutorial. Explains ActionForm Action Class Validation Framework.
 
Introduction to the JSP Java Server Pages
Introduction to the JSP Java Server Pages Welcome to JSP Section Introduction To JSP Java Server Pages or JSP for short is Sun's solution for developing dynamic web sites. JSP provide excellent server side scripting support for creating database
 
JSP FUNDAMENTALS
JSP FUNDAMENTALS JSP FUNDAMENTALS By: Hrishikesh Deshpande Introduction : JSP termed as Java Server Pages is a technology introduced by Sun Microsystems Inc. to develop the web application in more efficient way than Servlets. It has got many
 
Using Taglib in JSP. A brief introduction to taglibs and taglibs programing.
Using Taglib in JSP. A brief introduction to taglibs and taglibs programing. JSP TAG LIBRARIES JSP Tag Libraries : JSP’s offer a unique feature of “Tag Libraries”. Simply put, these are custom defined JSP tags. They are basically meant for
 
Introduction to JSP tags JSP Directives
Introduction to JSP tags JSP Directives INTRODUCTION TO JSP TAGS I n this lesson we will learn about the various tags available in JSP with suitable examples. In JSP tags can be devided into 4 different types. These are: Directives In the
 
Using Beans in JSP. A brief introduction to JSP and Java Beans.
Using Beans in JSP. A brief introduction to JSP and Java Beans. USING BEANS IN JSP Java Beans Java Beans are reusable components. They are used to separate Business logic from the Presentation logic. Internally, a bean is just an instance of a
 
Developing Simple Struts Tiles Application
Developing Simple Struts Tiles Application Developing Simple Struts Tiles Application Introduction In this section I will show you how to develop simple Struts Tiles Application. You will learn how to setup the Struts Tiles and create example
 
Site navigation
 

 

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2006. All rights reserved.