The BSF (Bean Scripting Framework) Tag Library enables JSP writers to write the code portion of their JSP in languages other than Java.
For a much more detailed description of BSF itself see http://alphaworks.ibm.com/tech/bsf, but here are a few key excerpts:
The Bean Scripting Framework (BSF) is an architecture for incorporating scripting into Java applications and applets. Scripting languages such as Netscape Rhino (Javascript), VBScript, Perl, Tcl, Python, NetRexx and Rexx are commonly used to augment an application's function or to script together a set of application components to form an application.
BSF supports both directions of scripting: in one case where the Java-side is in charge and runs/evaluates scripts at will, and in the other case the script runs and controls Java beans. Notice that while we use the word "bean", it is used loosely - BSF works with any Java object and not just a true bean.
BSF defines a set of JSP objects available as beans that are available for the scriptlet to use:
request
response
pageContext
application
out
config
page
exception
session
The BSF taglib also allows JSP writers to use multiple scripting languages within the same JSP document.
Follow these steps to configure your web application with this tag library:
/
bsf.tld
)
to the /WEB-INF
subdirectory of your web
application. /bsf
.jar
)
to the /WEB-INF/lib
subdirectory of your web
application. <taglib>
element to your web
application deployment descriptor in /WEB-INF/web.xml
like this: <taglib> <taglib-uri>http://jakarta.apache.org/taglibs/bsf-2.0</taglib-uri> <taglib-location>/WEB-INF/bsf.tld</taglib-location> </taglib>
To use the tags from this library in your JSP pages, add the following directive at the top of each page:
<%@ taglib uri="http://jakarta.apache.org/taglibs/bsf-2.0" prefix="x" %>
where "x" is the tag name prefix you wish to use for tags from this library. You can change this value to any prefix you like.
The BSF tag library includes several tags, with the following characteristics:
This tag is the BSF taglib equivalent of the "<%" JSP tag. There is one required attribute, "language", which defines the language used in that section of the JSP. For example:
<bsf:scriptlet language="tcl">
$out println "Hello world"
</bsf:scriptlet>
This tag is the BSF taglib equivalent of the "<%=" JSP tag. This is one required attribute, "language", which defines the language used in that section of the JSP. For example:
<bsf:expression language="perlscript">
CreateBean("java.util.Date")
</bsf:expression>
See the example JSP (bsf-examples\temps.jsp
) for
an example of the usage of the tags from this custom tag library.