Example: Converting JavaScript source to the Bean Scripting Framework
JavaScript code is one of the most popular languages of Web developers. This language supports the following base objects, plus additional objects from the Document Object Model:
- array
- date
- math
- number
- string
Server-side JavaScript code supports the same base objects, and additional objects that support user access to databases, file systems and e-mail systems. Like client-side JavaScript code, server-side JavaScript code is also platform, browser, and language independent.
You can convert server-side JavaScript applications to the Bean Scripting Framework. This topic describes how to perform this conversion.
Server-side JavaScript source code
Suppose you have the following server-side JavaScript application:
<html> <head> <title>Hello World server-side JavaScript example</title> </head> <body> <br><br> </body> </html> <server> function writePage() write("<center><font size='6'>Hello World</font></center>"); </server>Converting server-side JavaScript source code to the Bean Scripting Framework (BSF)
Make the following changes to the JavaScript source code to enable BSF:
<%@ page language="javascript" %> <html> <head> <title>Hello World server-side BSF/JavaScript example</title> </head> <body> <br><br> </body> </html> <% out.println("<center><font size='6'>Hello World</font></center>"); %>Review the other BSF reference articles for deployment information and additional programming examples.