Custom JSP taglib lets you present tag's body as XML data. This taglib lets you reuse the existing content in your Ajax applications for example. Tag presents own body as XML CDATA content, so your JavaScript XML parser will be able to extract HTML code wrapped by XML tags. For example, suppose your Ajax application needs to obtain HTML content prepared by JSP file and use this content for the updating some div block (via innerHtml property). In this case the requested JSP file must present own data in XML format. So without the converting it to XHTML you can simply
wrap it with Ajax preparation taglib:
<%@ taglib uri="taglib.tld" prefix="a" %> <a:toAjax tagName="mycode" contentType="true"> your HTML content is here </a:toAjax> In this case tag will produce the following XML file:
<?xml version="1.0" encoding="UTF-8"?> <mycode> <![CDATA[ your HTML content goes here ]]> </mycode> Now in your Ajax application you can get the value for node
mycode and it will keep the HTML content prepared in the requested JSP file.
The following code illustrates the main idea:
<!-- this block must be updated --> <div id="updateThis"></div> ... var req; <script language="JavaScript"> function callback() { if (req.readyState ==4) if (req.status==200) { xml = req.responseXML; html = xml.getElementsByTagName("mycode")[0]; document.getElementById("updateThis").innerHTML=html.childNodes[0].nodeValue; } } function callJSP() { if (window.XMLHttpRequest) req=new XMLHttpRequest(); else if (window.ActiveXObject) req=new ActiveXObject("Microsoft.XMLHTTP"); req.open("GET","our_file.jsp",true); req.onreadystatechange=callback; req.send(); } </script> Here req.open("GET","our_file.jsp",true) requests our JSP file. And Ajax preparation taglib lets you take the existing JSP code "as is" and return it in XML format. Function callback parses the response and obtains the value for XML tag mycode. You can perform the similar task with Java servlets filter. See Ajax preparation filter in JSOS. Tags are: toAjax Body tag presents own body as XML data. Parameters are: 1) tagName Optional parameter. Describes a name for your tag. Default value is text
for downloading: Library: toajaxtag.jar Description: taglib.tld See also Coldtags suite - the largest collection of custom JSP tags.
|
Also in Coldtags:
|