You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Harry Stangel <hs...@pacbell.net> on 2000/07/14 06:52:57 UTC

response.encodeURL supported?

I am experimenting with sessions and can't seem to get
response.encodeURL to work with my test servlet.  The 
servlet compiles and runs, but (with cookies turned off)
a new session is created with each hit and no session id
is appended.

I'm running Apache 1.3.12 with mod_rewrite loaded.
Following the advice in the FAQ, I appended this to the
end of httpd.conf:

    <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteRule ^(/.*;jsessionid=.*)$ $1 [T=jserv-servlet]
    </IfModule>

Running my test servlet in Tomcat 3.1 standalone mode
doesn't work either (should it?)
 
Am I missing something obvious?  TIA for any help...
-- Harry Stangel
 
------------------------------------------------------------
 
[a very simple test servlet]
 
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
 
public class encodeURLTest extends HttpServlet {

    int hits = 0;
    
    public void doGet(
        HttpServletRequest request, 
        HttpServletResponse response) 
        throws ServletException, IOException {

        HttpSession session = request.getSession(true);
        session.setAttribute("hits", new Integer(++hits));
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();

        out.print(
            "<html>" +
            "<head><title>encodeURL Test</title></head>" +
            "<body>" +
            "<h3>With browser set to refuse cookies, " +
            "reload this page</h3><hr>" +
            "<table cellpadding=\"4\">" +
            "<tr><td>session id:<td>" + 
                session.getId() + 
            "<tr><td>hits since servlet was loaded:<td>" + 
                session.getAttribute("hits") + 
            "<tr><td>new session?<td>" + 
                session.isNew() +
            "<tr><td>tracking from cookie?<td>" + 
                request.isRequestedSessionIdFromCookie() + 
            "<tr><td>tracking from encoded URL?<td>" + 
                request.isRequestedSessionIdFromURL() +
            "<tr><td><font color=\"red\">" +
                "this URL should be encoded:</font><td>" +
                
            //////////////////////////////////////////////

            response.encodeURL("/servlet/encodeURLTest") +  

            //////////////////////////////////////////////
                
            "</table></body></html>");
        out.close();
    }
}