BBjspWebSession::getAttribute (Deprecated)

The BBJSP system is deprecated. For new development, use BBxServlet.

Description

In BBj 16.0 and higher, this method returns the object bound with the specified name in this BBjspWebSession, or null if no object is bound under the name.

Syntax

Return Value

Method

Object

getAttribute(string name)

Parameters

Variable

Description

name

name of attribute to be retrieved

Return Value

the value bound to the name

Remarks

The example below shows getting the attribute ‘userID’ from the session within a BBJSP BBJSP Servlet.

Example

This example demonstrates how this works in a BBJSP web-page

<%@ taglib uri='/WEB-CFG/tld/core.tld' prefix='c' %>
<html>
    <body>
        <h1>Hello from BBJSP</h1>
        <ul>
            <c:iterate data="<%= #getSession().getAttributeNames() %>" id="name">
                <%
                    REM = Get the "name" from the page context
                    name$ = #PageContext!.getAttribute("name")
                %>
                <li><b>${name}</b> = <%= str(#getSessiont().getAttribute(name$)) %>
            </c:iterate>
        </ul>
    </body>
</html>

This example demonstrates how this works in a BBJSP servlet

class public MyServlet

  field private BBjspWebRequest request!
  field private BBjspWebResponse response!
  field private BBjspWebSession session!
  
  method public void service(BBjspServletContext context!)
       
    #request! = context!.getRequest()
    #response! = context!.getResponse()

    #session! = #request!.getSession()
    s! = #response!.getOutputStream()
    
    #response!.setContentType("text/html")
    
    s!.write("<html><body><h1>Hello from BBJSP</h1>")
    names! = #session!.getAttributeNames()
    if (names!.size()>0) then
      s!.write("<ul>")
      for i = 1 to names!.size()
        name$ = names!.get(i-1)
        s!.write("<li>"+name$ + ":" + session!.getAttribute(name$))
      next i
      s!.write("</ul>")
    else
      s!.write("<br/>No session variables!<br/>")
    endif
    s!.write("</body></html>")
  methodend
classend

See Also