JSP custom tag in Hindi

JSP custom tag in Hindi

JSP custom tag :-

custom tag user define tag है custom tag की सहायता से developer को back page पर ज्यादा अच्छा control मिलता है custom tag को reuse किया जा सकता है तथा इनका format दो प्रकार से बन सकता है

1.Empty tag:-

कोई body नहीं होती है

2.Body tag:-

जिसमें body होती हैं

Tag के attributes उसको बनाने पर निर्भर करते हैं इसके कुछ attributes निम्न है

  • Name:-

यह attribute का नाम define करता है

  • Required:-

यह बताता है कि attribute आवश्यक है true या यह मात्र एक option है (false)

  • Type:-

यह class का type दर्शाता है (इसकी default value string होती है )

  • Description:-

व्याख्या करना ।

  • Rtexprvalue:-

run time expiration value को declare करता है

Custom tag बनाने के लिए तीन component की आवश्यकता होती है

TagHandler class जो कि Simple Tag Support को extend करती है

TLD file ( tag library descriptor)

JSP file में लगा custom tag

1 TagHandler class को हम TagBody tag , Simple Tag Interface से implement कर सकते है तथा simple tag support class के method DoTag  को override किया जाता है

2  TDL file एक प्रकार की XML  document है जो कि library तथा उसमें मौजूद प्रत्येक Tag की information रखता है।

 

 Example of custom tag :-

माना की हम एक hello नाम का tag बनाना चाह रहे है जिसे directly < hello> tag use करना है

 

Import javaX.Servlet .JSP tagext.*;

Import javaX.Servlet.JSP.*;

Import Java.io.*;

Public Class Hello tag extend;

Simple Tag support

{

Public Void doTag ( ) throws JSP Exception;

{

JSP Write out = get JSPContext()get out();

Out.println (“Hello”);

}

}

 

 

 

Leave a Comment