Ajax eval taglib ver. 1.1

    Custom JSP taglib. This taglib is similar to our Eval taglib, but JSP code will be executed asynchronously via Ajax call. Tag AjaxEval allows you to evaluate JSP code in the dynamic. It is similar to the function eval() you may see for example in JavaScript and ColdFusion. So, you may accumulate any JSP code in the string variable and evaluate (execute) this JSP code.

For example:
Suppose you need to execute this JSP code:

    int i=1; i++; System.out.println("<br>i="+i);

<%@ taglib uri="taglib.tld" prefix="aexec" %>

   String s="&lt;% int i=1; i++; System.out.println(\"<br>i=\"+i);%&gt;";

<aexec:AjaxEval code="<%=s%>" />

Note: you have to use &lt; instead of < and &gt; instead of > in the string for JSP elements.

Tag AjaxEval can cache dynamic code. So if you are executing the same code several times you can avoid recompilations. In order to use cache you have to provide an additional parameter cacheDir. This parameter describes some existing directory in the file tree of your web application. Note: you have to provide here a path to this directory relatively to your jsp files. E.g. if you are using a subdirectory EVAL_CACHE within subdirectory DATA you can write so:

<aexec:AjaxEval code="<%=your_JSP_code%>" cacheDir="DATA/EVAL_CACHE"/>

Tag AjaxEvalPage lets you evaluate JSP page described in the parameter src.

Body tag AjaxEvalBody lets you evaluate own body twice. Suppose your JSP code (custom tags) outputs some JSP code (e.g. with scriptlets, tags etc.) rather than plain HTML. In this case you need to evaluate (execute) this output again. That is what evalBody tag is for. For example:

   String s1="System.out.println(\"Hello\")";

   <% out.println("<"+"% "+s1+";%"+">"); %>

Tag AjaxEvalBody evalutes own body twice. The first pass is synchronous and generates some JSP code. This generated code will be executed asynchronoulsy via Ajax call.

Note: if your evaluated code contains some custom taglibs make sure this code includes the definitions for taglibs too. It is not enough here to define taglibs in the main file only.

In order to use this tag you have to describe an external JavaScript file cjajax.js on your page.

Tags are:


Executes JSP code from the parameter. Parameter is:

1) code JSP code
2) cacheDir Optional parameter. Describes a directory for cache. By default is empty (tag does not use cache).


Executes JSP page. Parameters are:

1) src describes your JSP page


Body tag executes own body twice. Parameters are: none

for downloading:

Library: ajaxevaltag.jar    Description: taglib.tld   JavaScript library: cjajax.js

© Coldbeans Software      Comments?

See also Coldtags suite - the largest collection of custom JSP tags.