JSP and JSTL Tutorials - Tutorial Addendum - JSP Tag Aspect Administration

arcadegamesios wordgamesios lifestyleappsios
 31 December 18:00   

    



    



    



    

Tag Aspect Setter Method

    



    

The JSP tag addendum ability maps anniversary aspect encountered in a custom

    

tag to an acreage of the aforementioned name of the tag object. So if you wish

    

to use an aspect in a custom tag, you haveto ascertain a acreage in the tag class

    

with the aforementioned name as the attribute. Actuality is the accomplish you charge to follow

    

to add an aspect to a custom tag:

    



    

1. Ascertain a acreage in the tag chic with the aforementioned name as the aspect name

    

by abacus a setter adjustment and a getter method. This is the aforementioned way as defining

    

a acreage in a JavaBean class.

    



    

2. Add an "attribute" aspect central the "tag" aspect in your TLD book

    

with the afterward syntax:

    



    

<tag>

    

<name>tag_name</name>

    

<tag-class>class_full_name</tag-class>

    

<body-content>empty | jsp</body-content>

    

<attribute>

    

<name>attribute_name</name>

    

<required>true | false</required>

    

</attribute>

    

</tag>

    



    



    

3. Add the aspect to the custom tag in your JSP page. Then the tag is processed,

    

the setter adjustment of the tag item will be alleged to canyon the aspect amount

    

into the tag object.

    



    

Tag Aspect Setter Adjustment Archetype - EchoTag.java

    



    

To appearance you how to use attributes in a custom tag, I wrote the afterward archetype

    

tag, EchoTag.java. It does annihilation but takes the amount of the "message" attribute,

    

and echoes aback to the page achievement with characters reversed.

    

 

    

/**

    

* EchoTag.java

    

* Absorb (c) 2003 by Dr. Yang. All rights reserved.

    

*/

    

package ;

    

import java.io.*;

    

import javax.servlet.jsp.tagext.*;

    

public chic EchoTag extends TagSupport {

    

clandestine Cord bulletin = null;

    

accessible abandoned setMessage(String m) {

    

bulletin = m;

    

}

    

accessible int doStartTag() {

    

try {

    

if (message!=null) {

    

char[] a = message.toCharArray();

    

int n = a.length;

    

for (int i=0; i<n/2; i++) {

    

burn t = a[i];

    

a[i] = a[n-1-i];

    

a[n-i-1] = t;

    

}

    

pageContext.getOut().print(a);

    

pageContext.getOut().println("<br/>");

    

}

    

} bolt (IOException e) {

    

System.err.println(e.toString());

    

}

    

acknowledgment SKIP_BODY;

    

}

    

}

    



    



    

Here is the TLD file:

    

 

    

<?xml version="1.0"?>

    

<!DOCTYPE taglib Accessible

    

"-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"

    

"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_2.dtd">

    

<!-- HyTaglib.tld

    

Absorb (c) 2003 by Dr. Yang

    

-->

    

<taglib>

    

<tlib-version>1</tlib-version>

    

<jsp-version>1.2</jsp-version>

    

<short-name> s Tag Library</short-name>

    

<tag>

    

<name>echo</name>

    

<tag-class>.EchoTag</tag-class>

    

<body-content>empty</body-content>

    

<attribute>

    

<name>message</name>

    

<required>false</required>

    

</attribute>

    

</tag>

    

</taglib>

    



    



    

Here is a analysis page, EchoTagTest.jsp:

    

 

    

<?xml version="1.0"?>

    

<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"

    

xmlns:c="http://java.sun.com/jstl/core"

    

xmlns:hy="urn:jsptld:/WEB-INF/tlds/HyTaglib.tld" version="1.2">

    

<!-- EchoTagTest.jsp

    

Absorb (c) 2003 by Dr. Yang

    

-->

    

<jsp:directive.page contentType="text/html"/>

    

<html><body>

    

<hy:echo message="Fish, I adulation you and account you actual much."/>

    

</body></html>

    

</jsp:root>

    



    



    

You can assumption what you will be accepting if you admission this page.

    

(Continued on next part...)

    



    

 


Tags: class, content, custom, property, method, attribute, message, notes, public, tutorial, tutorials, object

 attribute, class, version, message, required, public, echotag, content, property, setter, custom, method, taglib, xmlns, copyright, object, name<, , < tag, name <, tag class, < body, < attribute, < jsp, attribute <, jsp tag, < name, tag attribute, custom tag, sun com, html <, java sun, http java, setter method, tag object, tag <, < body content, tag attribute setter, tag attribute handling, tutorials tutorial notes, jstl tutorials tutorial,

Share JSP and JSTL Tutorials - Tutorial Addendum - JSP Tag Aspect Administration:
Digg it!   Google Bookmarks   Del.icio.us   Yahoo! MyWeb   Furl  Binklist   Reddit!   Stumble Upon   Technorati   Windows Live   Bookmark

Text link code :
Hyper link code:

Also see ...

Permalink
Article In : Computers & Technology  -  jsp