code: public String encodeURL(String url) 
      {        
          // should not encode if cookies in evidence
          if (_servletHttpRequest==null ||
              _servletHttpRequest.isRequestedSessionIdFromCookie() &&
              _servletHttpRequest.getServletHandler().isUsingCookies())
              return url;        
          
          // get session;
          if (_session==null && !_noSession)
          {
              _session=_servletHttpRequest.getSession(false);
              _noSession=(_session==null);
          }
          
          // no session or no url
          if (_session == null || url==null)
              return url;
          
          // invalid session
          String id = _session.getId();
          if (id == null)
              return url;
          
          // Check host and port are for this server
          // TODO not implemented
          
          // Already encoded
          int prefix=url.indexOf(SessionManager.__SessionUrlPrefix);
          if (prefix!=-1)
          {
              int suffix=url.indexOf("?",prefix);
              if (suffix<0)
                  suffix=url.indexOf("#",prefix);
  
              if (suffix<=prefix)
                  return url.substring(0,prefix+SessionManager.__SessionUrlPrefix.length())+id;
              return url.substring(0,prefix+SessionManager.__SessionUrlPrefix.length())+id+
                  url.substring(suffix);
          }        
          
          // edit the session
          int suffix=url.indexOf('?');
          if (suffix<0)
              suffix=url.indexOf('#');
          if (suffix<0)
              return url+SessionManager.__SessionUrlPrefix+id;
          return url.substring(0,suffix)+
              SessionManager.__SessionUrlPrefix+id+url.substring(suffix);
      }
docs: /* ------------------------------------------------------------