W3C home > Mailing lists > Public > www-jigsaw@w3.org > September to October 1998

Problem passing parameter to servlet while handling a session

From: Gildas Mazery <mazery@agence.cpu.fr>
Date: Thu, 24 Sep 1998 11:22:30 -0400 (EDT)
Message-ID: <01BDE7DF.88597810@GILDAS3>
To: "'www-jigsaw@w3.org'" <www-jigsaw@w3.org>

To handle a session whithout cookies, servlets must add to all generated URL a 
session_id as a parameter. This is done by using the encodeUrl methode of 
HttpServletResponse. Depending whether URLs contain a parameter, on top of the
one set by encodeURL, or not, the servlets that are invoked by those generated
URLs can throw an execption when performing getParameter method. 

"encodeUrl" in JigsawHttpServletResponse assumes that URLs have no parameter,
and just add : 
at the end of URLs. If an URL passed to encodeUrl already has a parameter
then the resulting URL has a wrong format, and looks at :
The right URL should be :
since parameter list's separator is "&" and not "?". 

So, I have modified JigsawHttpServletResponse.java in the package 
org.w3c.jigsaw.servlet, replacing

    public String encodeUrl(String url) {
	if (! jrequest.isRequestedSessionIdFromCookie()) {
	    url = url +  "?" + jrequest.getCookieName()+"="+
	return url;
    public String encodeUrl(String url) {
	if (! jrequest.isRequestedSessionIdFromCookie()) {
	    url = url + (    url.indexOf("?") != -1    ? "&" : "?")
                 + jrequest.getCookieName()+"="+
	return url;

I don't know if the change is revelant, however the change is minor 
and then, the set of servlets a was testing (Duke's Bookstore of the
java.sun's tutorial) seems finally to work fine with a web browser
that refuse cookies. 
(In fact I also had to disable auto-load for the servletwrapper and 
add the servlet's directory to the CLASSPATH, to allow a servlet to
use an another one. This seems to be a bug in jigsaw's class_loader and  
the workaround is found in the mailing list archive). 

However, the code of the first servlet is suspect : encodeUrl is used before
creating a session. I am not sure that's a normal thing. 
I guess that's why the session is always handled by adding a parameter
to the URL, even if the browser accept cookies.
If I create a session in this servlet before using encodeUrl, 
or if I d'ont use encodeUrl in this servlet (in fact the servlet
generate a welcome page and a menu that does not need to be include
in a session) all things append as they are expected to, that is to
say : if the browser accept cookies, they are used for handling sessions,
if not, sessions are handled by adding parameter to generated URL.

To conclude, I wonder if there is a bug in the servlet or a bug in the 
default behaviour of encodeUrl when there is no session.


Received on Thursday, 24 September 1998 11:24:39 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 22:41:25 UTC