| |
Struts Tutorials:
Struts2 Tag CheckBoxList , Checkbox, Iterator, IF
Struts2 Tag Library Example
Struts2 Tiles Example
Struts2 Tiles I18N Example
Struts2 Questions
Struts Tiles I18N Example
Struts Eclipse MVC
Struts2 Tags
Struts2 Example and Tutorial
Struts MVC
Struts2 Validation
Hibernate Tutorials:
Hibernate Case Study
Class Hierarchy Persist Example
Using Hibernate Interceptor
Hibernate Questions with Answer
Hibernate Many-to-Many Mapping Example
Hibernate one-to-many Mapping Example
Hibernate and ORM tools
Spring Hibernate Example
Hibernate SessionFactory Example
Hibernate Mapping Class Hierarchy
Hibernate Questions
Hibernate SessionFactory Questions
Spring Hibernate Example:
Spring Hibernate Case Study
Written By : admin
Title :
Tag Library Simple Steps
Description :
JSP Servlet and Tag Library More...
|
Written By : Amit
Title :
Form based Security Web Application
Description :
Tomcat Example More...
|
Written By : Sameer
Title :
JavaServer Faces JSF
Description :
Benefits and comparing with JSP Technology More...
|
Written By : Amit
Title :
Quartz Scheduler Example
Description :
Load on startup More...
|
Written By : Amit
Title :
Web Load Test
Description :
Grinder WEB Load Testing Framework More...
|
| Tags/Keywords : JSP Tag Library, Example, Steps, Simple, Code, Tutorial, Article Author : admin Date (Year/Month/Date): 2009-01-25
JSP TAG Library - How can I create a JSP Tag library? | | | | |
|
How can I create a JSP Tag library?
In case of a HTML User Interface made of HTML code
and dynamic values from processing of components in
the business or application tier.
If not using Tag library, then one has to write
Java code in JSP or Servlet code, and this
way it is very hard to manage and changing layout
will be very difficult and error prone.
Tag library gives this advantage of placing
Java code in form of POJO (Plain Old Java Object)
classes and UI programmers with ways to write UI
using Tags, and this makes size of JSP file
quite small with flexibility of parameter passing
from JSP page to the TAG beans.
Please send your suggestions
to my email id .......
|
Different parts of the Tag libraries are as follows:
In order to be able to create or write a sample Tag
library, please take following steps as reference:
There are four major parts/items required for this sample
Tag library to work,
1. TLD file
2. POJO (Plain Old Java Object) that implements
javax.servlet.jsp.tagext.Tag
3. JSP file
4. Tag library supporting Web server
We shall be creating first three above items here, and the
web server I have used is TOMCAT.
Step 1.
Define your own tld file, name it as convenient.
(I have used JSP Tag Library 1.1)
Contents for thsi sample Tag library looks something
as follows:
----------------------------------------------------
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag
Library 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary__1_1.dtd">
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>DemoTags</shortname>
<tag>
<name>firsttag</name>
<tagclass>test.mytag.MyTag</tagclass>
<attribute>
<name>name</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
----------------------------------------------------
This TLD file contains information like the Tag name as "firsttag",
attribute name as "name" and whether this attribute is required
or optional etc.
One can create a file with extension ".tld" and place this under
WEB-INF folder, I did placed it under /WEB-INF/tlds/DemoTags.tld.
2. Now is the time to create test.mytag.MyTag POJO class that
contains logic for creation of the UI part of this sample MyTag.
Create a Java file that should implement javax.servlet.jsp.tagext.Tag.
as follows:
----------------------------------------------------
package test.mytag;
import java.io.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
public class MyTag implements Tag,Serializable
{
private PageContext pc=null;
private Tag parent = null;
private String name = null;
public void setName(String argName) {
name = argName;
}
public String getName()
{
return name;
}
public void setPageContext(PageContext p)
{
pc=p;
}
public void setParent(Tag t)
{
parent =t;
}
public Tag getParent()
{
return parent;
}
public int doStartTag() throws JspException
{
try{
pc.getOut().write("<table border=1>");
if(name != null)
pc.getOut().write("<tr><td>"+name+"</td></tr>");
pc.getOut().write("</table>");
}catch(IOException ex){
throw new JspTagException("An IOException occurred");
}
return SKIP_BODY;
}
public int doEndTag() throws JspException
{
return EVAL_PAGE;
}
public void release()
{
pc=null;
parent=null;
}
}
----------------------------------------------------
This Java file has to be copied under WEB-INF/classes
and then respective package folder.
In order to compile this MyTag code, one has to place
corresponding JSP Tag api Jar file, I found it under
<<TOMCAT_HOME_5.5>>/common/lib and a file "jsp-api.jar"
3.
By creating a jsp file and using the tag firsttag, as follows:
----------------------------------------------------
<html>
<body>
<%@ taglib uri="/WEB-INF/tlds/DemoTags.tld" prefix="mytag" %>
<mytag:firsttag name="xyz"/>
</body>
</html>
----------------------------------------------------
One can see the final output as a Table with a single cell as "xyz".
This is a very simple way of demonstrating how Tag library can be
used, one can explore many ways to create some complex UI,
depending on need.
| |
 | Author of this article/writeup has expressed his/her willingness |
to help or guide users with any technical difficulties he/she faces
while working with the example code environment setting up, running
and resolving any such exception raised during compile or at runtime.
You may ask for any technical doubt or seek technical help related to
this article by using following form to reach for technical help
from the Author for FREE.
This article's Author shall be reading your request and responding
within reasonable time (no resolution timeframe defined as such).
|
|
|
Commented By -> Umanath | Realy this is verry useful because i searched
many site and time but not simply and not
qiuckly read and learn. So "Realy good". Thanks
|
| | Are you interested in solving a very interesting Technology Stack while Playing this Game 
|
|
| Home >>> Web Technology >>> Tag Library Simple Steps >>> JSP Servlet and Tag Library |
|
|
Visitor/User referred related external URL:
(Visible upon review and approved by this site Administrator)
|
|
|
|
|
<- requires login | Log in or Register | |
Copyright © 2008-2009, Interview-Questions-Tips-Forum, All Rights Reserved. | CONTACT PRIVACY POLICY DISCLAIMER |
 |
Terms of Use and Disclaimer :
This web site provides some of the information about various technologies, example
code, tips, tutorials etc. Like any printed materials, content of these pages may
become out of date over a period of time. Therefore all visitor/users of this web
site are requested/advised to refer to the originating parties/sources for the
latest changes and happenings for detailed information. This information is not
intended to be a substitute for the original reference provided by the originating
parties/sources.
By accessing and using this website in any ways, including, without
limitation, browsing the website pages, using any information, using any content and/or
downloading any materials, you agree to and are bound by the terms of use
described in this page and Usage Terms and Conditions.
If you do not agree to all of
the terms and conditions contained in the terms of use described in this
page and Usage Terms and Conditions, do not use this
website in any manner. If you are using the website on behalf of your
employer, you represent that you are authorized to accept these Terms of Use
on your employer's behalf.
All Trademarks are property of their respective owner. Appropriate measure is being
taken for providing accurate and up-to-date information but like any printed materials,
these blog(s)/contents may eventually be outdated one day, so if you are using any
of these information, please refer original content/documentation from respective sources.
And under no circumstances shall the Author of these contents and/or this web site
be liable for any loss, damage, expense incurred or suffered which is claimed to have
occurred because of usage of the contents of this web site.
If you have any questions/queries/feedback/suggestions then please write to this web
site owner at contact.
|  |
|
|
|
|
|