BBxServletContext::getResponse

Description

In BBj 21.00 and higher, this method returns the BBxServletResponse object for the BBxServletContext.

Syntax

Return Value Method
BBxServletResponse getResponse()

Parameters

None.

Return Value

The BBxServletResponse object for the BBxServletContext.

Example

rem '/**

rem '* Enter the values for your username, password, and the filepath to this file
rem '*/
username$ = "admin"
password$ = "admin123"
pathToThisFile$ = "/path/to/BBxServletContextDemo.bbj"

context! = BBjAPI().getAdmin(username$, password$).getJettyServerConfig().getCustomContext("root")
context!.addBBxServlet("/BBxServletContextDemo", pathToThisFile$, "BBxServletContextDemo", "bbxServletContextDemo", 1)
BBjAPI().getAdmin(username$, password$).getJettyServer().getContext("root").restart()

CLASS PUBLIC BBxServletContextDemo

    rem 'Demonstration of various methods and functions of the BBxServletContext object
    METHOD PUBLIC VOID bbxServletContextDemo(BBxServletContext context!)

        rem 'The BBxServletRequest, BBxServletResponse, BBxWebSession, and BBjJettyContext are retrieved here
        request! = context!.getRequest()
        response! = context!.getResponse()
        session! = context!.getSession()
        bbjContext! = context!.getJettyContext()

        rem 'Get ServletOutputStream from BBxServletResponse
        out! = response!.getOutputStream()

        rem 'Output Label for BBxServlet Context section of of servlet page
        out!.write("<h2>BBxServletContext</h2>")
        out!.write("<p>When a BBxServlet runs, it receives a BBxServletContext object as the sole parameter in its ")
        out!.write("service method. The BBxServletContext object provides access to key elements of the BBxServlet ")
        out!.write("and BBjServices, including the BBxServletRequest, BBxServletResponse, BBxWebSession, and ")
        out!.write("BBjJettyContext objects. Demonstrated below is the additional information that can be accessed ")
        out!.write("through BBxServletContext.</p>")

        rem 'Method call for the getContextName() demo
        #getContextNameDemo(context!)
        out!.write("<p>See <code>getContextNameDemo</code> in source code for example.</p>")

        rem 'Method call for demo of  initialization parameter methods
        #initParametersMethodsDemo(context!)
        out!.write("<p>See <code>initParametersMethodsDemo</code> in source code for an example.</p>")
    METHODEND

    rem 'Demonstration of getContextName() method in BBxServletContext
    METHOD PUBLIC VOID getContextNameDemo(BBxServletContext context!)

        rem 'Get ServletOutputStream from BBxServletResponse
        out! = context!.getResponse().getOutputStream()

        rem 'Here is where we retrieve the context name for this servlet
        contextName$ = context!.getContextName()

        rem 'Output html for webpage that will be displayed
        out!.write("<h3>Context Name</h3>")
        out!.write("<p><code>getContextName()</code> returns a String representing the name of the context this ")
        out!.write("servlet was added to. See below for the context name of this particular servlet.</p> ")

        out!.write("<p><code>String getContextName() = "+contextName$+"</code></p>")

    METHODEND

    rem 'Demonstration of getInitParameter(String name) and getInitParameterNames() in BBxServletContext
    METHOD PUBLIC VOID initParametersMethodsDemo(BBxServletContext context!)

        rem 'Get ServletOutputStream from BBxServletResponse
        out! = context!.getResponse().getOutputStream()

        rem 'Get BBjVector of initialization parameter names
        paramNames! = context!.getInitParameterNames()

        rem 'Output initialization parameters label as well as
        out!.write("<h3>Initialization Parameters:</h3>")

        out!.write("<p>Initialization parameters are the parameters that were set at servlet creation time in either ")
        out!.write("the EM or the BBj console. Below are the return values of <code>getInitParameterNames</code> and ")
        out!.write("<code>getInitParamer(paramName$)</code> for this particular servlet.")

        out!.write("<code>")

        rem 'Create string to display return values
        if (paramNames!.size()>0) then
            out!.write("<ul>")
            initParamValueString$ = ""

            rem 'Loop over the parameter names and print them with their corresponding value
            FOR N=0 TO paramNames!.size()-1
                paramName$ = paramNames!.getItem(N)

                rem 'Retrieve initialization parameter with the given name
                paramValue$ = context!.getInitParameter(paramName$)

                rem 'add value to string of parameter values
                initParamValueString$ = initParamValueString$ + "<li>getInitParameter(<em>"+paramName$+"</em>) = "+paramValue$+"</li>"
            NEXT N

            rem 'Output parameter values to response output stream
            out!.write("<li>BBjVector getInitParameterNames() = "+paramNames!.toString()+"</li>")
            out!.write("<li>String getInitParameter(String name$):<ul>"+initParamValueString$+"</ul></li>")
            out!.write("</ul>")

        else
            out!.write("There are no initialization parameters for this servlet.")
        endif

        out!.write("</code>")
    METHODEND
CLASSEND

ClosedVersion History

  • BBj 21.00: BBxServlet introduced.

See Also

BBjAPI

BBxServlet

BBxServlet Tutorial

BBxServletContext

BBxServletResponse

BBxServletContext::getRequest

See the BBj Object Diagram for an illustration of the relationship between BBj Objects.