You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jason Johnston <Ja...@epa.state.il.us> on 2003/04/29 21:34:57 UTC

Parameter-Based Session Strings not Persistent, please help

I'm not sure what's going on but apparently I'm missing something.  I'm
puting together a simple Control servlet and I'm running into a strange
problem that seems to be defying me.

In my Servlet, I have a "mode" parameter that gets passed to the
control.  The servlet checks to see if there is a SecurityToken object
in the user's session.  If there is not, then if stashes the mode in the
session object as a String ( It also stashes severl other strings as
well.) and then forwards to an Authentication Servlet.  

The Auth Servlet builds the SecurityToken and places it back in the
Session object.  It then forwards back to the Servlet that called it.  

However this time, since there is a SecurityToken in the session, it
just retrieves the various strings from the session and prints them out.
 The very strange thing is that the "mode" string is being returned as
null.  All other strings seem to survive the double-forward fine, but
the one based on the parameter is null.

To make things even stranger, if I change the test from simple:

if(securitytoken==null) {...}

to

if((securitytoken==null) && (mode.equalsIgnoreCase("2")) {...}

Everything works fine (provided the URL has ?mode=2), the "mode" string
survives the forwarding.  I'm obviously not understanding something
about the parameter/session/forward paradigm but I've read all pertinent
reference material and this seems to be "contrary" behavior.

Here is the code for the Control Servlet.  This is where I suspect the
problem is, but I'm not sure where.

 protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
    throws ServletException, java.io.IOException {

       SecurityToken
st=(SecurityToken)request.getSession().getAttribute("security");
       if(st==null)
        {
            String fstring="/servlet/ctlInventory";
            String ourl=request.getRequestURL().toString();
            String fred=request.getParameter("mode");
            String ouri=request.getRequestURI();
            request.getSession().setAttribute("forward",fstring);
            request.getSession().setAttribute("ourl",ourl);
            request.getSession().setAttribute("ouri",ouri);
            request.getSession().setAttribute("fred",fred);
            request.setAttribute("forward",fstring);
            RequestDispatcher
rd=getServletContext().getRequestDispatcher("/servlet/authenticate");
            rd.forward(request,response);   
        }
        else{ 
        String mode=request.getParameter("mode");
       
if(mode==null){mode=(String)request.getSession().getAttribute("mode");}
        if(mode==null){mode="unknown";}
        String url=request.getRequestURL().toString();
        String ourl=(String)request.getSession().getAttribute("ourl");
        String ouri=(String)request.getSession().getAttribute("ouri");
        String
omode=(String)request.getSession().getAttribute("mode");
        String
newfred=(String)request.getSession().getAttribute("fred");
        String
fstring=(String)request.getSession().getAttribute("forward");
        java.io.PrintWriter out = response.getWriter();
        response.setContentType("text/html");
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet</title>");  
        out.println("</head>");
        out.println("<body>");
        out.println("You have been successfully forwarded to the
inventory control servlet.");
        out.println("<br>Mode="+mode);
        out.println("<br>Requested URL="+url);
        out.println("<br>Original URL="+ourl);
        out.println("<br>Original URI="+ouri);
        out.println("<br>Original Mode="+omode);
        out.println("<br> Forward="+fstring);
        out.println("<br>fred = "+newfred);
        if(st==null)
        { out.println("<br>Security Token is null.");
        }else{out.println("<br>Security Token is not null.");}
        out.println("</body>");
        out.println("</html>");
        out.close();
        }
    } 



Thanks ahead of time to anyone willing to share insight.


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org