BBjspWebResponse::encodeURL (Deprecated)

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

Description

In BBj 16.0 and higher, this method encodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged. The implementation of this method includes the logic to determine whether the session ID needs to be encoded in the URL. For example, if the browser supports cookies, or session tracking is turned off, URL encoding is unnecessary.

For robust session tracking, all URLs emitted by a servlet should be run through this method. Otherwise, URL rewriting cannot be used with browsers which do not support cookies.

Syntax

Return Value

Method

String

encodeURL(string url)

Parameters

Variable

Description

url

the url to be encoded.

Return Value

the encoded URL if encoding is needed; the unchanged URL otherwise.

Remarks

The example below shows encoding a URL for redirect

Example

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

<html>
    <body>
        <h1>Hello from BBJSP</h1>
        <a href='<%= #Response!.encodeURL("/servlet/anotheServlet?wibble=123") %>'>Click</a>
    </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>")
    s!.write("<a href='")
    s!.write(#response!.encodeURL("/servlet/anotheServlet?wibble=123"))
    s!.write("'>Click</a>")
    s!.write("</body></html>")
  methodend
classend

See Also

BBJSP

BBjspWebRequest

BBjspWebResponse