BBjCookie

Creation


BBjServletEvent

|

+-- BBjHttpResponse

        |

    +-- BBjCookie

Description

In BBj 12.0 and higher, BBjCookie creates a cookie, a small amount of information sent by a servlet to a Web browser, saved by the browser, and later sent back to the server. A cookie's value can uniquely identify a client, so cookies are commonly used for session management.

A cookie has a name, a single value, and optional attributes such as a comment, path and domain qualifiers, a maximum age, and a version number. Some Web browsers have bugs in how they handle the optional attributes, so use them sparingly to improve the interoperability of your servlets.

The servlet sends cookies to the browser which adds fields to HTTP response headers to send cookies to the browser, one at a time. The browser is expected to support 20 cookies for each Web server, 300 cookies total, and may limit cookie size to 4 KB each.

The browser returns cookies to the servlet by adding fields to HTTP request headers. Cookies can be retrieved from a request by using the BBjHttpRequest::getCookies() method. Several cookies might have the same name but different path attributes.

Creation

A BBjCookie object is obtained with the following BBjHttpResponse method:

Return Value

Method

BBjCookie

addCookie(string name)

Methods of BBjCookie

Return Value

Method

string

getComment()

string

getDomain()

int

getMaxAge()

string

getName()

string

getPath()

boolean

isSecure()

string

getValue()

int

getVersion()

void

setComment(string purpose)

void

setDomain(string domain)

void

setMaxAge(int expiry)

void

setPath(string uri)

void

setSecure(boolean secure)

void

setValue(string value)

void

setVersion(int version)

Remarks

None.

Example

REM Obtain the instance of the BBjAPI object

LET myAPI!=BBjAPI()

MyServlet! = new MyServlet()

 

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

 

PROCESS_EVENTS

 

class public MyServlet

  method public void myMethod(BBjServletEvent p_event!)

      LET chan = UNT

      request! = p_event!.getBBjHttpRequest()

      response! = p_event!.getBBjHttpResponse()

      resp!.setContentType("text/html")

      open(chan)"JSERVLET"

      print(chan)”<html><body><h1>Hello BBj!”

      close(chan)

  methodend

classend

See Also

BBjAPI

BBjHttpRequest

BBjHttpResponse

BBjServletEvent

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