The BeanShell Servlet and Web Applications

The BeanShell Servlet and Web Applications


The following is a small test servlet and webapp example for BeanShell. You can use it to try BeanShell in your app server and execute scripts inside the running container dynamically. (This can save you a lot of deployment and re-deployment time during development).

The BeanShell servlet accepts some text via an HTTP POST, evaluates it capturing stdout and stderr, and shows you the results including any return value. (The servlet also tells you the version of BeanShell that it is using, which is useful if your container also includes BeanShell.)

The servlet provides a simple form that you can use to post a script with various options. You can also use the bsh.Remote client to post a script from the command line to a remote app server and fetch the results, including a numeric return value.

Please see the BeanShell User Manual, Servlet Section for instructions on using the Remote command and the BeanShell Servlet facilities.

The source for the servlet is in the BeanShell source distribution. You can also grab the compiled example WAR file here. There are two versions - one that comes with the BeanShell JAR included in the WAR file and one that expects the BeanShell JAR to be in the app server's classpath:

http://www.beanshell.org/bshservlet.war

(With bsh-xxx included)

http://www.beanshell.org/bshservlet-wbsh.war

If you grab the latter you may want to rename it to simply "bshservlet.war".

Deploy the WAR in your app server (likely just drop the war file in the correct place) and then direct your browser to /bshservlet/index.html for instructions.

Again, please see the BeanShell User Manual, Servlet Section for more details.