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:









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






<required>true | false</required>








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;










} bolt (IOException e) {






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"




<!-- HyTaglib.tld


Absorb (c) 2003 by Dr. Yang










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
























Here is a analysis page, EchoTagTest.jsp:




<?xml version="1.0"?>


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




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"/>




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








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 ...

Article In : Computers & Technology  -  jsp