InfoCenter Home >
4: Developing applications >
4.2: Building Web applications >
4.2.5: Using the Bean Scripting Framework >
4.2.5.1: BSF examples and samples
4.2.5.1: BSF examples and samples
There are no WebSphere Application Server implementation restrictions on using BSF.
Invoke BSF as you would any other Web application, using the instructions in the
article Installing application files to administer your application.
To test these code samples, from a Browser window,
copy the code samples and paste them into your own file. You can use any file name, but the
file extension must be .jsp. To see the results, the file must be served
from a server with a JSP engine, such as WebSphere Application Server.
The following steps and code samples describe how to implement BSF:
- Create a JSP file
- Change the Java code to JavaScript
- Add the required BSF tag as illustrated in the View 2 sample
- Add the file to the Web application document root directory
- Invoke the code.
See the file JSP access models for more JSP information.
- Create a JSP file that looks like this next example:
<html>
<head>
<title> Temperature Table using Java >/title>
</head>
<body>
<h1>Temperature Table using Java</h1>
<p>American tourists visiting Canada can use this handy temperature
table which converts from Fahrenheit to Celsius:
<br> <br>
<table BORDER COLS=2 WIDTH="20%" >
<tr BGCOLOR="#FFFF00">
<th>Fahrenheit</th>
<th>Celsius</th>
</tr>
<%
for (int i=0; i<101; i+=10) {
out.println ("<tr ALIGN=RIGHT BGCOLOR=\"#CCCCCC\">");
out.println ("<td>" + i + "</td>");
out.println ("<td>" + ((i - 32)*5/9) + "</td>");
out.println ("</tr>");
}
%>
</table>
<p><i> <%= new java.util.Date () %> </i></p>
</body>
</html>
|
- Change the Java code in the previous file to JavaScript
so the file now looks like the following example:
<%@ page language="javascript" %>
|
<html>
<head>
<title> Temperature Table using JavaScript >/title>
</head>
<body>
<h1>Temperature Table using JavaScript</h1>
<p>American tourists visiting Canada can use this handy temperature
table which converts from Fahrenheit to Celsius:
<br> <br>
<table BORDER COLS=2 WIDTH="20%" >
<tr BGCOLOR="#FFFF00">
<th>Fahrenheit</th>
<th>Celsius</th>
</tr>
<%
for (var i=0; i<101; i+=10) {
out.println ("<tr ALIGN=RIGHT BGCOLOR=\"#CCCCCC\">");
out.println ("<td>" + i + "</td>");
out.println ("<td>" + Math.round((i - 32)*5/9) + "</td>");
out.println ("</tr>");
}
%>
</table>
<p><i> <%= new java.util.Date () %> </i></p>
</body>
</html>
|
- The only BSF-specific tag that is required in your file is
<%@ page language="javascript" %>
This tag identifies the language to BSF. View 2 illustrates where this
tag is located in the file.
|
|