BBjspWebRequest::getLocales


Description

In BBj 16.0 and higher, this method returns the a BBjVector containing Locale objects indicating, in decreasing order starting with the preferred locale, the locales that are acceptable to the client based on the Accept-Language header. If the client request doesn't provide an Accept-Language header, this method returns an Enumeration containing one Locale, the default locale for the server.

Syntax

Return Value

Method

BBjVector

getLocales()

Parameters

None.

Return Value

a BBjVector containing the Locale(s)

Remarks

The example below shows getting the locale(s) from a BBjspWebRequest within a 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="<%= #getRequest().getLocales() %>" id="locale">
                <li>${locale}' />
            </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()

    #response!.setContentType("text/html")
    s! = #response!.getOutputStream()
    
    s!.write("<html><body><h1>Hello from BBJSP</h1>")
    vectLocales! = #request!.getLocales()
    sz = vectLocales!.size()
    if sz then
      s!.write("Locales:")
      s!.write("<ul>")
      for i = 0 to sz - 1
        s!.write("<li>" + str(vectLocales!.get(i)))
      next i
      s!.write("</ul>")
    endif
    s!.write("Locale:" + str(#request!.getLocale()))
    s!.write("</body></html>")
  methodend
classend

See Also

BBJSP

BBjspWebRequest

BBjVector