BBjServlet Overview (Deprecated)

BBjServlets are deprecated for BBj 21.00 and higher, and have been replaced by BBxServlets.

In BBj 12.0 and higher, BBjServlet allows programs to respond to web requests such as events. For additional reading about BBjServlets, read these articles from The BASIS International Advantage:

To respond to a web request, follow these three steps:

  1. Create an application with BBjAppConfig

  2. Obtain the servlet registry from BBjAdmin

  3. Publish the BBjAppConfig with the BBjServletRegistry


BBj applications can require a lot of configuration. config files, working directories, program names, just to get started. The BBjAppConfig object encapsulates environment information and stores it so the program can be run in an automatic way, much like an autorun program, or BBj task.


The BBjServletRegistry manages all currently running servlets. The BBjServletRegistry is used to publish BBjAppConfigs at specific paths. It is obtained from BBjAdmin, so administrative rights are required to add and remove servlets from the webserver.


With both the BBjServletRegistry and your BBjAppConfig, you can publish a new servlet to the webserver. Select a path (starting with “/servlet/”) and publish your application. New interpreters will be started and pooled depending on load. When the load declines, the interpreters will be shut down. Licenses are checked out only during request handling.

declare BBjAdmin admin!

declare BBjServletRegistry registry!

declare BBjConfig config!

declare BBjAppConfig application!


REM create

config! = BBjAPI().getConfig()

application! = config!.makeEmptyAppConfig()



REM obtain

admin! = BBjAPI().getAdmin("admin", "admin123")

registry! = admin!.getServletRegistry()


REM publish

registry!.unpublish("/example", err=*next)

registry!.publish("/example", application!)

What can servlets do?

Servlets can respond to all types of web requests such as GET and  POST. In order to respond to a web request, your servlet must register for the ON_WEB_CONNECTION event. That event provides lots of information about the request, such as the request method, query parameters and http headers.

When you’re ready to respond, print to the new JSERVLET channel, the output will be redirected back to the browser with whatever configuration options you wish to set on the BBjHttpResponse, such as contentType.


data! = BBjAPI().getServletData()

MyServlet! = new MyServlet()

data!.setCallback(data!.ON_WEB_CONNECTION, myServlet!, "myMethod")


class public MyServlet
   field private BBjInt chan%
   method public MyServlet()
       #chan% = unt
   method public void myMethod(BBjServletEvent p_event!)
       req! = p_event!.getHttpRequest()
       resp! = p_event!.getHttpResponse()
       #listItem("method", req!.getMethod())

   method public void listItem(BBjString p_title$, BBjString p_item$)
       print(#chan%)p_title$, ":",p_item$

   method public void parameterList(BBjHttpRequest req!)
       names! = req!.getParameterNames()
       if names!.size() > 0
           for i = 0 to names!.size() - 1
               rem alternatively, req!.getParameterValues(param$)
               rem for multi valued params
               #listItem(names!.get(i), req!.getParameter(names!.get(i)))
           next i

   method public void headerList(BBjHttpRequest req!)
       names! = req!.getHeaderNames()
       if names!.size() > 0
           for i = 0 to names!.size() - 1
               rem alternatively, req!.getHeaders(param$)
               rem for multi valued headers
               #listItem(names!.get(i), req!.getHeader(names!.get(i)))
           next i



See Also










The BASIS International Advantage