SlideShare ist ein Scribd-Unternehmen logo
1 von 71
{
Implementing JSP
Tag Extensions
CUSTOM TAGS
 User Defined tags
 Reduce the use of scripting elements
in a JSP page
 Allows to create new and reusable tags
 Can use in any JSP page with the help
of tag libraries
 A Tag library provides the capability to
define new customized tags
 Major features of custom tags:
 Reusability
 Readability
 Maintainability
 Portabiltity
Exploring the Elements of Tag
Extensions
 The TLD file
 The tag handler
 The taglib directive
Basic elements of Custom tags
 XML document describing tag library
 Provides documentation of tag library and
version information of JSP container
 Contains the name of TagLibraryValidator
class
The TLD file
 Used to implement the functionality of a custom
tag
 To set a custom tag in a JSP page,
<%@ taglib prefix=“p” uri=“Mytld.tld” %>
 Features:
 Declares that a tag library is used
 Identifies the location of the tag library
 Associates a tag prefix with the usage of
actions in the library
The taglib directive
 Java class where a custom tag is defined
 Can define tag handlers by implementing interfaces
or by extending an abstract base class from
javax.servlet.jsp.tagext package
 Various tag handler interfaces are Tag, BodyTag,
IterationTag and SimpleTag
 JSP technology defines 2 types of tag handlers:
 Classic tag handler
 Simple tag handler
The Tag handler
Exploring the Tag Extension API
 The tag extension API provides the
javax.servlet.jsp.tagext package.
 Contains various classes and interfaces
 Similar to HTML/XML tags
Terms associated with the
implementation of a tag extension
 Tag name-combination of prefix and suffix,separated
by a colon.
For example :-
<jsp:forward />tag
 Attributes-refers to a value that is assigned to an
attribute of a tag.
 Nesting-process in which a tag is used within
another.
 For example, <jsp:param />tag is used within
<jsp:include /> and <jsp:forward />tags
 Body content-refers to content,such as expressions
and scriplets.
The tag Extension Interfaces
§ The Tag interface
§ The JspTag interface
§ The IterationTag interface
§ The BodyTag interface
§ The DynamicAttributes interface
§ The SimpleTag interface
§ The TryCatchFinally interface
§ The JspIdConsumer interface
1. The Tag interface
Basic protocol between tag handler and a JSP
page.
 dostartTag() and doEndTag()
 setParent(tag t)
 getParent()
 release()
Describing the Fields of the Tag
interfaces
 EVAL_BODY_INCLUDE
 EVAL_PAGE
 SKIP_BODY
 SKIP_PAGE
2. The JspTag Interface
 Serves as a base interface for the Tag and
SimpleTag interface.
 Used for organizational and type-safety purposes.
 BodyTag,IterationTag,SimpleTag and Tag -
interfaces are sub-interfaces.
3. The IterationTag interface
 Build tag handlers that repeatedly re-evaluate the body of a
custom tag.
 Extends the Tag interface.
 Method:
 doAfterBody()
 Fields:
 EVAL_BODY_AGAIN-Re-evaluates the body content.
 SKIP_BODY-stops the evaluation of the body content.
4. The BodyTag Interface
 Extends the Iteration Tag interface.
 Methods:
doInitBody() - evaluates the body of a custom tag
before initializing it,not invoked for empty tag.
setBodyContent(BodyContent b)-sets the body
content of the custom tag.
5. The DynamicAttributes interface
 To provide support for dynamic attributes.
 SetDynamicAttribute() avoids the translation-
time errors.
 JspException exception is thrown.
6. The simpleTag Interface
 Created by implementing the SimpleTag interface.
 Methods:
 doTag() - evaluating and iterating the body content
of a tag.
 getParent() - returns the parent of the custom tag.
 setJspBody - provides the body of the custom tag as
a JspFragment object.
7. The TryCatchFinally Interface
 To handle the exceptions that may occur within the tag
handler class.
 doStartTag() and doEndTag() may throw JspException.
 Methods:
doCatch()-invoked whenever there an exception arises
during the evaluation of the body of the current tag.
doFinally()-gets invoked after the processing of the
doEndTag() method is complete.
8. The JspIdConsumer Interface
 Jsp container should provide a compiler generated id .
 JspId attribute is a string value,similar to <jsp:id>tag
 Difference is <jsp:id> is evaluated at the execution time.
 provides single method,setJspId(string id)
 Unique id during translation process.
The Tag Extension Classes
The TagSupport Class
 Is an abstract class that implements the tag as well as
IterationTag interfaces and provides support for all
the methods.
 Static method
 Methods:
 doAfterBody()-body content of the tag after the
invocation of the doStartTag()
 doEndTag()-returns EVAL_PAGE field,by default,on
executing the end tag.
 doStartTag()-SKIP_BODY field after the execution of the
start tag.
 getValue()- returnsng string value.
 getId()-returns values of the id attribute/null value
 getValues()-get the corresponding values
 removeValue(java.lang.string k)-removes the string
value.
 setId(java.lang.string Id)-Sets the id attribute.
 setPageContext()-Sets the page context.
 Fields
 Id-specifies a String value for a tag
 PageContext-provides access to al the namespaces and
page attributes.
The BodyContent Class
 Is a subclass of the JspWriter class and encapsulates
the evaluation of the body of an action.
 pushBody() or popBody()-creates instances of the
BodyContent class
 Methods:
 getReader()-Returns the value of the BodyContent object
as a Reader object.
 getString()-as a string
 writeOut(java.io.Writer out)-writes the content of the
BodyContent object into a writer object.
 getEnclosingWriter()-enclosing JspWriter object.
 clearBody()-clrs the body of the buffer.
The BodyTagSupport Class
 Implements the BodyTag interface .
 Acts as a base class to create tag handlers without
defining each method of the BodyTag interface
8.11
The FunctionInfo Class
 Provides information abt a function defined in the tag
library.
 Instantiated from the TLD file.
 Available only at the time of translation of a JSP
page.
 Methods
 getFunctionClass() - Returns the class of a function.
 getFunctionSignature() - signature.
 getName - Name
The JspFragment class
 Encapsulates the jsp code in an object that can be
invoked multiple times.
 Manually either by page author or by TLD file.
 Methods:
 getJspContext()-returns the JspContext object that is used
by the current JspFragment object.
 Invoke(java.io.Writer out)-Executes the JspFragment
object.
The SimpleTagSupport Class
 Implements the SimpleTag interface
 Provides the defination for all the implemented
methods of the SimpleTag interface.
 Methods:
 doTag() -processes a simple tag handler.
 getJspBody() -returns a fragment that encapsulates the
body passed by the container.
 getJspContext()-returns the page context.
 getParent()-parent tag of a simple tag.
 setJspBody(JspFragment jspBody)-stores the specified
JspFragment object.
 setJspContext(JspContext pc)-stores the provided JSP
context in the private JspContext.
 setParent(JspTag parent)-sets the parent tag of the simple
tag.
The TagAdapter class
 Allows the collaboration bw classic tag handlers and
simple tag handlers.
 Methods:
 getAdaptee()-instance of simple tag handler that is
being adapted to the tag interface.
 getParent()-returns the parent of the simple tag.
The TaglibraryInfo class
 Provides translation-time information associated
with a taglib directive and TLD.
8.16
8.17
The TagInfo Class
 Provides information of a specific tag provided in a
tag library.
 Instance of TLD.
8.18
8.19
The TagFileInfo Class
 Provides information about a tag file in a tag library.
 TLD instantiates,available only at translation time.
 Code Snippet
 TagFileInfo(name, path, Taginfo)
 Methods:
 getName()-returns a unique action name of the tag.
 getPath()-path to locate the .tagfile.
 getTagInfo()object containing the information abt the tag.
The TagAttributeInfo Class
 Contains information abt tag attributes.
 ID as its attribute.
 Specifies a string value for a custom tag.
The TagExtraInfo Class
 Provides a mechanism to validate custom tags using tag
attributes in TLD.
 The <attribute>tag contains a set of three tags,
name> ,<required> and<rtexprvalue>
 Low level validation mechanism.
 Methods:
 getTagInfo()-returns TagInfo object of the custom tag.
 getVariableInfo(Tagdata data)-a zero length array,if no
scripting variables are defined.
 isValid(Tagdata data)-instance is valid.
 setTagInfo(Taginfo tagInfo)-sets the specied TagInfo
for the custom tag handler.
The PageData Class
 Provides the translation-time information on a JSP
page.
 Provides a single method i,e getInputStream().
 Returns an input stream of a JSP page in the form of
XML and stream encoding is done in UTF-8
The VariableInfo Class
 Determines the type of the scripting variables that are
created or modified by a tag at runtime
 Class should be provided in the classpath of the web
application.
The TagData Class
 Object of TD is used as an argument in the Validate(),
isValid(),getVariableInfo() methods of the TagExtraInfo
class at the translation time.
The TagLibraryValidator Class
 Validates a JSP page during the translation time.
 Validate(String prefix,String uri,PageData page)
 First two parameters are used to indicate how a tag
library is mapped in the jsp page.
 Last parameter is used to represent the XML view of the
page being validated.
The ValidationMessage Class
 Is a piece of information that is provided by either the
TagLibraryValidator or the TagExtraInfo object.
 JSP container can also use this VM obj to retrieve
information abt the location of errors.
 Methods:
 getId()-returns <jsp:id> attribute.
 getMessage()-localized validation message.
 Java class that implements the Tag, IterationTag
or BodyTag interface
Working with Classic Tag
Handlers
 Steps to develop the ClassicTag application:
 Creating the Tag handler for ClassicTag
application
 Creating TLD for ClassicTag application
 Creating html file for ClassicTag application
 Creating JSP file for ClassicTag application
 Configuring web.xml file for ClassicTag
application
 Defining the directory structure of ClassicTag
application
 Packaging, running and deploying the
ClassicTag application
Implementing Classic Tags
CustomMessage.java
package com.kogent.tags;
import javax.servlet.ServletRequest;
import javax.servlet.jsp.tagext.*;
public class CustomMessage extends BodyTagSupport
{
String pname;
private static final long serialVersionUID = 1L;
public void setParamName(String s)
{
pname=s;
}
public String getParamName()
{
return pname;
}
public int doStartTag()
{
ServletRequest req=pageContext.getRequest();
String pvalue=req.getParameter(pname);
if ((pvalue.equals("japan")) || (pvalue.equals("Japan")))
{
return EVAL_BODY_INCLUDE;
}
else
{
return SKIP_BODY;
}
} //doStartTag//doStartTag
public int doAfterBody()
{
return SKIP_BODY;
}//doAfterBody
public int doEndTag()
{
return EVAL_PAGE;
}//doEndTag
}
CustomTags.tld
<?xml version="1.0" ?>
<jsp-version>2.1</jsp-version>
<tlib-version>1.1</tlib-version>
<short-name>tag</short-name>
<tag>
<name>check</name>
<tag-class>com.kogent.tags.CustomMessage</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>check</name>
<required>true</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
</tag>
</taglib>
<html>
<body>
<form action="TestPage.jsp">
<b> PREDICT AND WIN !!! </b>
<BR/>
<BR/>
<p style="color:blue">The country which is known as "land of rising
sun" </p>
<input type="text" name="opt"/>
<input type="submit" value="check"/>
</form>
</body>
</html>
Home.html
<%@taglib uri="/WEB-INF/CustomTags.tld" prefix="tag"%>
<html>
<body>
<tag:check paramName = "opt">
<b>congratulations you have won a prize!!!</b>
</tag:check>
</body>
</html>
TestPage.jsp
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<welcome-file-list>
<welcome-file>home.html</welcome-file>
</welcome-file-list>
</web-app>
Web.xml
Displaying the Directory structure of Classic tag application
Output
 Java class that implements the SimpleTag interface
 The javax.servlet.jsp.tagext.SimpleTagSupport class
provides default implementation of all methods in
simple tags
Working with Simple Tag
Handlers
 Steps to develop the SimpleTag application:
 Creating the Tag handler for SimpleTag application
 Creating TLD for SimpleTag application
 Creating JSP file for SimpleTag application
 Configuring web.xml file for SimpleTag application
 Defining the directory structure of SimpleTag
application
 Packaging, running and deploying the SimpleTag
application
Implementing Simple Tags
package com.kogen.tags;
import javax.servlet.jsp.tagext.*;
import javax.servlet.jsp.*;
import java.io.*;
import java.util.Date;
public class CustomMessage1 extends SimpleTagSupport
{
public void doTag() throws JspException,IOException {
JspContext context=getJspContext();
JspWriter Out=context.getOut();
Out.println("Welcome!!! You are visting this Web page on"+new
Date());
}
}
CustomMessage1.java
<?xml version="1.0" ?>
<taglib version="2.1" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee/web-
jsptaglibrary_2_ 1.xsd">
<jsp-version>2.1</jsp-version>
<tlib-version>1.1</tlib-version>
<short-name>tag</short-name>
<tag>
<name>CustomMessage1</name>
<tag-class>com.kogent.tags.CustomMessage1</tag-class>
<body-content>empty</body-content>
</tag>
</taglib>
CustomTags.tld
<%@ taglib uri="/WEB-INF/CustomTags.tld" prefix="tag"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
<body>
<tag:CustomMessage1/><br>
</body>
</html>
test.jsp
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<welcome-file-list>
<welcome-file>test.jsp</welcome-file>
</welcome-file-list>
</web-app>
Web.xml
Displaying the Directory structure of Simple tag application
Output:
1. What are the major features of custom tags?
2. What are the 3 basic elements of custom tags?
3. What is TLD file?
4. Tell me any 1 feature of taglib directive.
………..?
Thank you

Weitere ähnliche Inhalte

Was ist angesagt?

Easy Steps to implement UDP Server and Client Sockets
Easy Steps to implement UDP Server and Client SocketsEasy Steps to implement UDP Server and Client Sockets
Easy Steps to implement UDP Server and Client Socketsbabak danyal
 
APPLICATIONS OF PERVASIVE COMPUTING.pptx
APPLICATIONS OF PERVASIVE COMPUTING.pptxAPPLICATIONS OF PERVASIVE COMPUTING.pptx
APPLICATIONS OF PERVASIVE COMPUTING.pptxJerlin Sundari
 
fhir-documents
fhir-documentsfhir-documents
fhir-documentsDevDays
 
The impact of web on ir
The impact of web on irThe impact of web on ir
The impact of web on irPrimya Tamil
 
Intruders and Viruses in Network Security NS9
Intruders and Viruses in Network Security NS9Intruders and Viruses in Network Security NS9
Intruders and Viruses in Network Security NS9koolkampus
 
Information retrieval-systems notes
Information retrieval-systems notesInformation retrieval-systems notes
Information retrieval-systems notesBAIRAVI T
 
Corba concepts & corba architecture
Corba concepts & corba architectureCorba concepts & corba architecture
Corba concepts & corba architecturenupurmakhija1211
 
Content addressable network(can)
Content addressable network(can)Content addressable network(can)
Content addressable network(can)Amit Dahal
 
IT- 328 Web Administration (Practicals)
IT- 328 Web Administration (Practicals)IT- 328 Web Administration (Practicals)
IT- 328 Web Administration (Practicals)Dushmanta Nath
 
Implementing and managing Content Management Systems
Implementing and managing Content Management SystemsImplementing and managing Content Management Systems
Implementing and managing Content Management SystemsR Sundara Rajan
 
Synchronization in distributed computing
Synchronization in distributed computingSynchronization in distributed computing
Synchronization in distributed computingSVijaylakshmi
 
component based development model
component based development modelcomponent based development model
component based development modelMuneeba Qamar
 
Topic #3 of outline Server Environment.pptx
Topic #3 of outline Server Environment.pptxTopic #3 of outline Server Environment.pptx
Topic #3 of outline Server Environment.pptxAyeCS11
 
Software engineering project management
Software engineering project managementSoftware engineering project management
Software engineering project managementjhudyne
 

Was ist angesagt? (20)

GFS & HDFS Introduction
GFS & HDFS IntroductionGFS & HDFS Introduction
GFS & HDFS Introduction
 
Easy Steps to implement UDP Server and Client Sockets
Easy Steps to implement UDP Server and Client SocketsEasy Steps to implement UDP Server and Client Sockets
Easy Steps to implement UDP Server and Client Sockets
 
APPLICATIONS OF PERVASIVE COMPUTING.pptx
APPLICATIONS OF PERVASIVE COMPUTING.pptxAPPLICATIONS OF PERVASIVE COMPUTING.pptx
APPLICATIONS OF PERVASIVE COMPUTING.pptx
 
fhir-documents
fhir-documentsfhir-documents
fhir-documents
 
The impact of web on ir
The impact of web on irThe impact of web on ir
The impact of web on ir
 
Intruders and Viruses in Network Security NS9
Intruders and Viruses in Network Security NS9Intruders and Viruses in Network Security NS9
Intruders and Viruses in Network Security NS9
 
Information retrieval-systems notes
Information retrieval-systems notesInformation retrieval-systems notes
Information retrieval-systems notes
 
HCI
HCI HCI
HCI
 
Corba concepts & corba architecture
Corba concepts & corba architectureCorba concepts & corba architecture
Corba concepts & corba architecture
 
Content addressable network(can)
Content addressable network(can)Content addressable network(can)
Content addressable network(can)
 
IT- 328 Web Administration (Practicals)
IT- 328 Web Administration (Practicals)IT- 328 Web Administration (Practicals)
IT- 328 Web Administration (Practicals)
 
Implementing and managing Content Management Systems
Implementing and managing Content Management SystemsImplementing and managing Content Management Systems
Implementing and managing Content Management Systems
 
1. GRID COMPUTING
1. GRID COMPUTING1. GRID COMPUTING
1. GRID COMPUTING
 
03 cia
03 cia03 cia
03 cia
 
WS - Security
WS - SecurityWS - Security
WS - Security
 
Software documentation
Software documentationSoftware documentation
Software documentation
 
Synchronization in distributed computing
Synchronization in distributed computingSynchronization in distributed computing
Synchronization in distributed computing
 
component based development model
component based development modelcomponent based development model
component based development model
 
Topic #3 of outline Server Environment.pptx
Topic #3 of outline Server Environment.pptxTopic #3 of outline Server Environment.pptx
Topic #3 of outline Server Environment.pptx
 
Software engineering project management
Software engineering project managementSoftware engineering project management
Software engineering project management
 

Andere mochten auch

Critical thinking in Node.js
Critical thinking in Node.jsCritical thinking in Node.js
Critical thinking in Node.jsMorgan Cheng
 
Realtime web open house
Realtime web open houseRealtime web open house
Realtime web open houseRan Wahle
 
Cckt 2006 2010
Cckt 2006   2010Cckt 2006   2010
Cckt 2006 2010papered
 
In Situ Bioremediation: When Does It Work?
In Situ Bioremediation: When Does It Work?In Situ Bioremediation: When Does It Work?
In Situ Bioremediation: When Does It Work?Zohaib HUSSAIN
 
What’s new in ECMAScript 6.0
What’s new in ECMAScript 6.0What’s new in ECMAScript 6.0
What’s new in ECMAScript 6.0Eyal Vardi
 
Why TypeScript?
Why TypeScript?Why TypeScript?
Why TypeScript?FITC
 
Hyderabad LISS III Image Interpretation (Using ERDAS Imagine)
Hyderabad LISS III Image Interpretation (Using ERDAS Imagine)Hyderabad LISS III Image Interpretation (Using ERDAS Imagine)
Hyderabad LISS III Image Interpretation (Using ERDAS Imagine)Prachi Mehta
 
Bec pelc+2010+-+science+and+health
Bec pelc+2010+-+science+and+healthBec pelc+2010+-+science+and+health
Bec pelc+2010+-+science+and+healthtitserchriz Gaid
 
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...탑크리에듀(구로디지털단지역3번출구 2분거리)
 
Application of Basic Remote Sensing in Geology
Application of Basic Remote Sensing in GeologyApplication of Basic Remote Sensing in Geology
Application of Basic Remote Sensing in GeologyUzair Khan
 
JavaScript Debugging Tips & Tricks
JavaScript Debugging Tips & TricksJavaScript Debugging Tips & Tricks
JavaScript Debugging Tips & TricksSunny Sharma
 
Typescript Fundamentals
Typescript FundamentalsTypescript Fundamentals
Typescript FundamentalsSunny Sharma
 

Andere mochten auch (19)

Fractal
FractalFractal
Fractal
 
Critical thinking in Node.js
Critical thinking in Node.jsCritical thinking in Node.js
Critical thinking in Node.js
 
Realtime web open house
Realtime web open houseRealtime web open house
Realtime web open house
 
Cckt 2006 2010
Cckt 2006   2010Cckt 2006   2010
Cckt 2006 2010
 
In Situ Bioremediation: When Does It Work?
In Situ Bioremediation: When Does It Work?In Situ Bioremediation: When Does It Work?
In Situ Bioremediation: When Does It Work?
 
Resume
ResumeResume
Resume
 
What’s new in ECMAScript 6.0
What’s new in ECMAScript 6.0What’s new in ECMAScript 6.0
What’s new in ECMAScript 6.0
 
Why TypeScript?
Why TypeScript?Why TypeScript?
Why TypeScript?
 
Hyderabad LISS III Image Interpretation (Using ERDAS Imagine)
Hyderabad LISS III Image Interpretation (Using ERDAS Imagine)Hyderabad LISS III Image Interpretation (Using ERDAS Imagine)
Hyderabad LISS III Image Interpretation (Using ERDAS Imagine)
 
Protocolos
ProtocolosProtocolos
Protocolos
 
ERDAS IMAGINE
ERDAS IMAGINEERDAS IMAGINE
ERDAS IMAGINE
 
Bec pelc+2010+-+science+and+health
Bec pelc+2010+-+science+and+healthBec pelc+2010+-+science+and+health
Bec pelc+2010+-+science+and+health
 
Oraclesql
OraclesqlOraclesql
Oraclesql
 
Network Security Terminologies
Network Security TerminologiesNetwork Security Terminologies
Network Security Terminologies
 
GEOLOGICAL - MINING EXPLORATION
GEOLOGICAL - MINING EXPLORATION GEOLOGICAL - MINING EXPLORATION
GEOLOGICAL - MINING EXPLORATION
 
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...
 
Application of Basic Remote Sensing in Geology
Application of Basic Remote Sensing in GeologyApplication of Basic Remote Sensing in Geology
Application of Basic Remote Sensing in Geology
 
JavaScript Debugging Tips & Tricks
JavaScript Debugging Tips & TricksJavaScript Debugging Tips & Tricks
JavaScript Debugging Tips & Tricks
 
Typescript Fundamentals
Typescript FundamentalsTypescript Fundamentals
Typescript Fundamentals
 

Ähnlich wie Implement JSP Tag Extensions

Introduction to JSP
Introduction to JSPIntroduction to JSP
Introduction to JSPGeethu Mohan
 
Bt0083 server side programing 2
Bt0083 server side programing  2Bt0083 server side programing  2
Bt0083 server side programing 2Techglyphs
 
Advance java session 15
Advance java session 15Advance java session 15
Advance java session 15Smita B Kumar
 
Session 9 : intro to custom tags-classic tag - Giáo trình Bách Khoa Aptech
Session 9 : intro to custom tags-classic tag - Giáo trình Bách Khoa AptechSession 9 : intro to custom tags-classic tag - Giáo trình Bách Khoa Aptech
Session 9 : intro to custom tags-classic tag - Giáo trình Bách Khoa AptechMasterCode.vn
 
Jsp , javasportal, jsp basic,
Jsp , javasportal, jsp basic, Jsp , javasportal, jsp basic,
Jsp , javasportal, jsp basic, rupendra1817
 
Eclipse Day India 2011 - Extending JDT
Eclipse Day India 2011 - Extending JDTEclipse Day India 2011 - Extending JDT
Eclipse Day India 2011 - Extending JDTdeepakazad
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2wiradikusuma
 
JSP Standard Tag Library
JSP Standard Tag LibraryJSP Standard Tag Library
JSP Standard Tag LibraryVISHAL DONGA
 
jstl ( jsp standard tag library )
jstl ( jsp standard tag library )jstl ( jsp standard tag library )
jstl ( jsp standard tag library )Adarsh Patel
 
Jsp standard tag_library
Jsp standard tag_libraryJsp standard tag_library
Jsp standard tag_libraryKP Singh
 

Ähnlich wie Implement JSP Tag Extensions (20)

Jstl 8
Jstl 8Jstl 8
Jstl 8
 
Jsp tag library
Jsp tag libraryJsp tag library
Jsp tag library
 
Introduction to JSP
Introduction to JSPIntroduction to JSP
Introduction to JSP
 
Jsp session 9
Jsp   session 9Jsp   session 9
Jsp session 9
 
Introduction to JSP.pptx
Introduction to JSP.pptxIntroduction to JSP.pptx
Introduction to JSP.pptx
 
JSP : Creating Custom Tag
JSP : Creating Custom Tag JSP : Creating Custom Tag
JSP : Creating Custom Tag
 
Bt0083 server side programing 2
Bt0083 server side programing  2Bt0083 server side programing  2
Bt0083 server side programing 2
 
Advance java session 15
Advance java session 15Advance java session 15
Advance java session 15
 
Session 9 : intro to custom tags-classic tag - Giáo trình Bách Khoa Aptech
Session 9 : intro to custom tags-classic tag - Giáo trình Bách Khoa AptechSession 9 : intro to custom tags-classic tag - Giáo trình Bách Khoa Aptech
Session 9 : intro to custom tags-classic tag - Giáo trình Bách Khoa Aptech
 
Jsp , javasportal, jsp basic,
Jsp , javasportal, jsp basic, Jsp , javasportal, jsp basic,
Jsp , javasportal, jsp basic,
 
JSP
JSPJSP
JSP
 
Eclipse Day India 2011 - Extending JDT
Eclipse Day India 2011 - Extending JDTEclipse Day India 2011 - Extending JDT
Eclipse Day India 2011 - Extending JDT
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2
 
JSP Standard Tag Library
JSP Standard Tag LibraryJSP Standard Tag Library
JSP Standard Tag Library
 
Biopython
BiopythonBiopython
Biopython
 
Session_15_JSTL.pdf
Session_15_JSTL.pdfSession_15_JSTL.pdf
Session_15_JSTL.pdf
 
jstl ( jsp standard tag library )
jstl ( jsp standard tag library )jstl ( jsp standard tag library )
jstl ( jsp standard tag library )
 
Jsp standard tag_library
Jsp standard tag_libraryJsp standard tag_library
Jsp standard tag_library
 
J2ee standards > CDI
J2ee standards > CDIJ2ee standards > CDI
J2ee standards > CDI
 
4. jsp
4. jsp4. jsp
4. jsp
 

Mehr von Soujanya V

Asymptotic analysis
Asymptotic analysisAsymptotic analysis
Asymptotic analysisSoujanya V
 
Implementing java server pages standard tag library v2
Implementing java server pages standard tag library v2Implementing java server pages standard tag library v2
Implementing java server pages standard tag library v2Soujanya V
 
Load balancing
Load balancingLoad balancing
Load balancingSoujanya V
 
Bigdataissueschallengestoolsngoodpractices 141130054740-conversion-gate01
Bigdataissueschallengestoolsngoodpractices 141130054740-conversion-gate01Bigdataissueschallengestoolsngoodpractices 141130054740-conversion-gate01
Bigdataissueschallengestoolsngoodpractices 141130054740-conversion-gate01Soujanya V
 

Mehr von Soujanya V (7)

Decision tree
Decision treeDecision tree
Decision tree
 
Asymptotic analysis
Asymptotic analysisAsymptotic analysis
Asymptotic analysis
 
Implementing java server pages standard tag library v2
Implementing java server pages standard tag library v2Implementing java server pages standard tag library v2
Implementing java server pages standard tag library v2
 
Filter
FilterFilter
Filter
 
Load balancing
Load balancingLoad balancing
Load balancing
 
Bigdataissueschallengestoolsngoodpractices 141130054740-conversion-gate01
Bigdataissueschallengestoolsngoodpractices 141130054740-conversion-gate01Bigdataissueschallengestoolsngoodpractices 141130054740-conversion-gate01
Bigdataissueschallengestoolsngoodpractices 141130054740-conversion-gate01
 
Filter
FilterFilter
Filter
 

Kürzlich hochgeladen

8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitterShivangiSharma879191
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catcherssdickerson1
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHC Sai Kiran
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncssuser2ae721
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
An introduction to Semiconductor and its types.pptx
An introduction to Semiconductor and its types.pptxAn introduction to Semiconductor and its types.pptx
An introduction to Semiconductor and its types.pptxPurva Nikam
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 

Kürzlich hochgeladen (20)

8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECH
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
An introduction to Semiconductor and its types.pptx
An introduction to Semiconductor and its types.pptxAn introduction to Semiconductor and its types.pptx
An introduction to Semiconductor and its types.pptx
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 

Implement JSP Tag Extensions

  • 2. CUSTOM TAGS  User Defined tags  Reduce the use of scripting elements in a JSP page  Allows to create new and reusable tags  Can use in any JSP page with the help of tag libraries
  • 3.  A Tag library provides the capability to define new customized tags  Major features of custom tags:  Reusability  Readability  Maintainability  Portabiltity Exploring the Elements of Tag Extensions
  • 4.  The TLD file  The tag handler  The taglib directive Basic elements of Custom tags
  • 5.  XML document describing tag library  Provides documentation of tag library and version information of JSP container  Contains the name of TagLibraryValidator class The TLD file
  • 6.  Used to implement the functionality of a custom tag  To set a custom tag in a JSP page, <%@ taglib prefix=“p” uri=“Mytld.tld” %>  Features:  Declares that a tag library is used  Identifies the location of the tag library  Associates a tag prefix with the usage of actions in the library The taglib directive
  • 7.  Java class where a custom tag is defined  Can define tag handlers by implementing interfaces or by extending an abstract base class from javax.servlet.jsp.tagext package  Various tag handler interfaces are Tag, BodyTag, IterationTag and SimpleTag  JSP technology defines 2 types of tag handlers:  Classic tag handler  Simple tag handler The Tag handler
  • 8. Exploring the Tag Extension API  The tag extension API provides the javax.servlet.jsp.tagext package.  Contains various classes and interfaces  Similar to HTML/XML tags
  • 9. Terms associated with the implementation of a tag extension  Tag name-combination of prefix and suffix,separated by a colon. For example :- <jsp:forward />tag  Attributes-refers to a value that is assigned to an attribute of a tag.
  • 10.  Nesting-process in which a tag is used within another.  For example, <jsp:param />tag is used within <jsp:include /> and <jsp:forward />tags  Body content-refers to content,such as expressions and scriplets.
  • 11. The tag Extension Interfaces § The Tag interface § The JspTag interface § The IterationTag interface § The BodyTag interface § The DynamicAttributes interface § The SimpleTag interface § The TryCatchFinally interface § The JspIdConsumer interface
  • 12. 1. The Tag interface Basic protocol between tag handler and a JSP page.  dostartTag() and doEndTag()  setParent(tag t)  getParent()  release()
  • 13. Describing the Fields of the Tag interfaces  EVAL_BODY_INCLUDE  EVAL_PAGE  SKIP_BODY  SKIP_PAGE
  • 14. 2. The JspTag Interface  Serves as a base interface for the Tag and SimpleTag interface.  Used for organizational and type-safety purposes.  BodyTag,IterationTag,SimpleTag and Tag - interfaces are sub-interfaces.
  • 15. 3. The IterationTag interface  Build tag handlers that repeatedly re-evaluate the body of a custom tag.  Extends the Tag interface.  Method:  doAfterBody()  Fields:  EVAL_BODY_AGAIN-Re-evaluates the body content.  SKIP_BODY-stops the evaluation of the body content.
  • 16. 4. The BodyTag Interface  Extends the Iteration Tag interface.  Methods: doInitBody() - evaluates the body of a custom tag before initializing it,not invoked for empty tag. setBodyContent(BodyContent b)-sets the body content of the custom tag.
  • 17. 5. The DynamicAttributes interface  To provide support for dynamic attributes.  SetDynamicAttribute() avoids the translation- time errors.  JspException exception is thrown.
  • 18. 6. The simpleTag Interface  Created by implementing the SimpleTag interface.  Methods:  doTag() - evaluating and iterating the body content of a tag.  getParent() - returns the parent of the custom tag.  setJspBody - provides the body of the custom tag as a JspFragment object.
  • 19. 7. The TryCatchFinally Interface  To handle the exceptions that may occur within the tag handler class.  doStartTag() and doEndTag() may throw JspException.  Methods: doCatch()-invoked whenever there an exception arises during the evaluation of the body of the current tag. doFinally()-gets invoked after the processing of the doEndTag() method is complete.
  • 20. 8. The JspIdConsumer Interface  Jsp container should provide a compiler generated id .  JspId attribute is a string value,similar to <jsp:id>tag  Difference is <jsp:id> is evaluated at the execution time.  provides single method,setJspId(string id)  Unique id during translation process.
  • 21. The Tag Extension Classes The TagSupport Class  Is an abstract class that implements the tag as well as IterationTag interfaces and provides support for all the methods.  Static method  Methods:  doAfterBody()-body content of the tag after the invocation of the doStartTag()
  • 22.  doEndTag()-returns EVAL_PAGE field,by default,on executing the end tag.  doStartTag()-SKIP_BODY field after the execution of the start tag.  getValue()- returnsng string value.  getId()-returns values of the id attribute/null value  getValues()-get the corresponding values
  • 23.  removeValue(java.lang.string k)-removes the string value.  setId(java.lang.string Id)-Sets the id attribute.  setPageContext()-Sets the page context.  Fields  Id-specifies a String value for a tag  PageContext-provides access to al the namespaces and page attributes.
  • 24. The BodyContent Class  Is a subclass of the JspWriter class and encapsulates the evaluation of the body of an action.  pushBody() or popBody()-creates instances of the BodyContent class
  • 25.  Methods:  getReader()-Returns the value of the BodyContent object as a Reader object.  getString()-as a string  writeOut(java.io.Writer out)-writes the content of the BodyContent object into a writer object.  getEnclosingWriter()-enclosing JspWriter object.  clearBody()-clrs the body of the buffer.
  • 26. The BodyTagSupport Class  Implements the BodyTag interface .  Acts as a base class to create tag handlers without defining each method of the BodyTag interface
  • 27. 8.11
  • 28. The FunctionInfo Class  Provides information abt a function defined in the tag library.  Instantiated from the TLD file.  Available only at the time of translation of a JSP page.
  • 29.  Methods  getFunctionClass() - Returns the class of a function.  getFunctionSignature() - signature.  getName - Name
  • 30. The JspFragment class  Encapsulates the jsp code in an object that can be invoked multiple times.  Manually either by page author or by TLD file.  Methods:  getJspContext()-returns the JspContext object that is used by the current JspFragment object.  Invoke(java.io.Writer out)-Executes the JspFragment object.
  • 31. The SimpleTagSupport Class  Implements the SimpleTag interface  Provides the defination for all the implemented methods of the SimpleTag interface.  Methods:  doTag() -processes a simple tag handler.  getJspBody() -returns a fragment that encapsulates the body passed by the container.
  • 32.  getJspContext()-returns the page context.  getParent()-parent tag of a simple tag.  setJspBody(JspFragment jspBody)-stores the specified JspFragment object.  setJspContext(JspContext pc)-stores the provided JSP context in the private JspContext.  setParent(JspTag parent)-sets the parent tag of the simple tag.
  • 33. The TagAdapter class  Allows the collaboration bw classic tag handlers and simple tag handlers.  Methods:  getAdaptee()-instance of simple tag handler that is being adapted to the tag interface.  getParent()-returns the parent of the simple tag.
  • 34. The TaglibraryInfo class  Provides translation-time information associated with a taglib directive and TLD.
  • 35. 8.16
  • 36. 8.17
  • 37. The TagInfo Class  Provides information of a specific tag provided in a tag library.  Instance of TLD.
  • 38. 8.18
  • 39. 8.19
  • 40. The TagFileInfo Class  Provides information about a tag file in a tag library.  TLD instantiates,available only at translation time.  Code Snippet  TagFileInfo(name, path, Taginfo)
  • 41.  Methods:  getName()-returns a unique action name of the tag.  getPath()-path to locate the .tagfile.  getTagInfo()object containing the information abt the tag.
  • 42. The TagAttributeInfo Class  Contains information abt tag attributes.  ID as its attribute.  Specifies a string value for a custom tag.
  • 43.
  • 44. The TagExtraInfo Class  Provides a mechanism to validate custom tags using tag attributes in TLD.  The <attribute>tag contains a set of three tags, name> ,<required> and<rtexprvalue>  Low level validation mechanism.
  • 45.  Methods:  getTagInfo()-returns TagInfo object of the custom tag.  getVariableInfo(Tagdata data)-a zero length array,if no scripting variables are defined.  isValid(Tagdata data)-instance is valid.  setTagInfo(Taginfo tagInfo)-sets the specied TagInfo for the custom tag handler.
  • 46. The PageData Class  Provides the translation-time information on a JSP page.  Provides a single method i,e getInputStream().  Returns an input stream of a JSP page in the form of XML and stream encoding is done in UTF-8
  • 47. The VariableInfo Class  Determines the type of the scripting variables that are created or modified by a tag at runtime  Class should be provided in the classpath of the web application.
  • 48. The TagData Class  Object of TD is used as an argument in the Validate(), isValid(),getVariableInfo() methods of the TagExtraInfo class at the translation time.
  • 49. The TagLibraryValidator Class  Validates a JSP page during the translation time.  Validate(String prefix,String uri,PageData page)  First two parameters are used to indicate how a tag library is mapped in the jsp page.  Last parameter is used to represent the XML view of the page being validated.
  • 50. The ValidationMessage Class  Is a piece of information that is provided by either the TagLibraryValidator or the TagExtraInfo object.  JSP container can also use this VM obj to retrieve information abt the location of errors.  Methods:  getId()-returns <jsp:id> attribute.  getMessage()-localized validation message.
  • 51.  Java class that implements the Tag, IterationTag or BodyTag interface Working with Classic Tag Handlers
  • 52.  Steps to develop the ClassicTag application:  Creating the Tag handler for ClassicTag application  Creating TLD for ClassicTag application  Creating html file for ClassicTag application  Creating JSP file for ClassicTag application  Configuring web.xml file for ClassicTag application  Defining the directory structure of ClassicTag application  Packaging, running and deploying the ClassicTag application Implementing Classic Tags
  • 53. CustomMessage.java package com.kogent.tags; import javax.servlet.ServletRequest; import javax.servlet.jsp.tagext.*; public class CustomMessage extends BodyTagSupport { String pname; private static final long serialVersionUID = 1L; public void setParamName(String s) { pname=s; }
  • 54. public String getParamName() { return pname; } public int doStartTag() { ServletRequest req=pageContext.getRequest(); String pvalue=req.getParameter(pname); if ((pvalue.equals("japan")) || (pvalue.equals("Japan"))) { return EVAL_BODY_INCLUDE; }
  • 55. else { return SKIP_BODY; } } //doStartTag//doStartTag public int doAfterBody() { return SKIP_BODY; }//doAfterBody public int doEndTag() { return EVAL_PAGE; }//doEndTag }
  • 57. <html> <body> <form action="TestPage.jsp"> <b> PREDICT AND WIN !!! </b> <BR/> <BR/> <p style="color:blue">The country which is known as "land of rising sun" </p> <input type="text" name="opt"/> <input type="submit" value="check"/> </form> </body> </html> Home.html
  • 58. <%@taglib uri="/WEB-INF/CustomTags.tld" prefix="tag"%> <html> <body> <tag:check paramName = "opt"> <b>congratulations you have won a prize!!!</b> </tag:check> </body> </html> TestPage.jsp
  • 59. <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <welcome-file-list> <welcome-file>home.html</welcome-file> </welcome-file-list> </web-app> Web.xml
  • 60. Displaying the Directory structure of Classic tag application
  • 62.  Java class that implements the SimpleTag interface  The javax.servlet.jsp.tagext.SimpleTagSupport class provides default implementation of all methods in simple tags Working with Simple Tag Handlers
  • 63.  Steps to develop the SimpleTag application:  Creating the Tag handler for SimpleTag application  Creating TLD for SimpleTag application  Creating JSP file for SimpleTag application  Configuring web.xml file for SimpleTag application  Defining the directory structure of SimpleTag application  Packaging, running and deploying the SimpleTag application Implementing Simple Tags
  • 64. package com.kogen.tags; import javax.servlet.jsp.tagext.*; import javax.servlet.jsp.*; import java.io.*; import java.util.Date; public class CustomMessage1 extends SimpleTagSupport { public void doTag() throws JspException,IOException { JspContext context=getJspContext(); JspWriter Out=context.getOut(); Out.println("Welcome!!! You are visting this Web page on"+new Date()); } } CustomMessage1.java
  • 65. <?xml version="1.0" ?> <taglib version="2.1" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee/web- jsptaglibrary_2_ 1.xsd"> <jsp-version>2.1</jsp-version> <tlib-version>1.1</tlib-version> <short-name>tag</short-name> <tag> <name>CustomMessage1</name> <tag-class>com.kogent.tags.CustomMessage1</tag-class> <body-content>empty</body-content> </tag> </taglib> CustomTags.tld
  • 66. <%@ taglib uri="/WEB-INF/CustomTags.tld" prefix="tag"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <link rel="stylesheet" type="text/css" href="mystyle.css"> </head> <body> <tag:CustomMessage1/><br> </body> </html> test.jsp
  • 67. <?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <welcome-file-list> <welcome-file>test.jsp</welcome-file> </welcome-file-list> </web-app> Web.xml
  • 68. Displaying the Directory structure of Simple tag application
  • 70. 1. What are the major features of custom tags? 2. What are the 3 basic elements of custom tags? 3. What is TLD file? 4. Tell me any 1 feature of taglib directive. ………..?