Note that there are some explanatory texts on larger screens.

plurals
  1. POServlet's sendRedirect() kills my session attributes
    primarykey
    data
    text
    <p>I am working on a webapp in WinXP, Eclipse Indigo and Google web plugin.</p> <p>I have a simple form that takes a value from user (e.g email) , passes it to a servlet named <code>SignIn.java</code> that processes it and saves the email value to the session. The <code>SignIn</code> code is very simple , here is what its <code>doGet</code> mostly does:</p> <pre><code>String email = req.getParameter("email"); //getting the parameter from html form ... ... HttpSession session = req.getSession(); //create a new session session.setAttribute("email", email); </code></pre> <p>So far so good, I've verified that the values aren't <code>null</code> at this point. Now comes the problem, I want to redirect to another servlet (<code>ShowOnline.java</code>) that needs to do some more processing. When I write</p> <pre><code>resp.sendRedirect(resp.encodeRedirectURL("/ShowOnlineServlet")); </code></pre> <p><code>ShowOnline</code> gets <code>null</code> session values (the same email attribute I saved a second before is now <code>null</code>)</p> <p>When I write </p> <pre><code>getServletConfig().getServletContext().getRequestDispatcher("/ShowOnlineServlet"); </code></pre> <p>everything is OK, the email attribute from before isn't <code>null</code>!</p> <p>What is going on? <code>sendRedirect()</code> just makes your browser send a new request, it shouldn't affect the session scope. I have checked the cookies and they are fine (it is the same session from before for sure since it is the first and only session my webapp creates and furthermore I even bothered and checked the sesison ID's and they're the same on both requests).</p> <p>Why would there be a difference between <code>sendRedirect()</code> and <code>forward()</code>? The easy solution would be to use <code>forward()</code> but I want to get to the bottom of this before I just let go , I think it is important for me to understand what happened. I'm not sure I like the idea of not knowing what's going on on such basic concepts (my whole webapp is very simple and basic at this point since I'm a beginner).</p> <p>Any thoughts ideas or suggestions would be warmly welcome !</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload