#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    5
    Rep Power
    0

    I have different session ID


    I use request.getSession(true);
    bet almost every time i got a different session ID.
    what could be the mistake?
  2. #2
  3. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,898
    Rep Power
    3887
    It's possible your session has timed out so your getSession(true) creates a new one. Try to set the lifetime of your session:
    Code:
    session.setMaxInactiveInterval(seconds)
    'seconds' should be an int value, specifying the number of seconds the session should last for after it's last been used.
    ~ishnid
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    5
    Rep Power
    0
    Thanks a lot ishnid I will check if this was my fault.
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    5
    Rep Power
    0
    I tried the following code, but everytime I got a different ID:

    package coreservlets;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;

    public class Servlet1 extends HttpServlet {
    private static final String CONTENT_TYPE = "text/html";
    //Initialize global variables
    public void init() throws ServletException {
    }
    //Process the HTTP Get request
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    HttpSession session=request.getSession();
    session.setMaxInactiveInterval(600);
    String s=session.getId();
    response.setContentType(CONTENT_TYPE);
    PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<head><title>Servlet1</title></head>");
    out.println("<body>");
    out.println("<br>"+s+"<br>");
    out.println("<p>The servlet has received a GET. This is the reply.</p>");
    out.println("</body></html>");
    }
    //Clean up resources
    public void destroy() {
    }
    }
  8. #5
  9. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    You are saying that you get a new session id even when you merely hit the retry button? You are not saying that you get a new session id when you go to that servlet in a new browser window are you? Because if you are openeing a new browser you will indeed get a new session id.
  10. #6
  11. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,898
    Rep Power
    3887
    From the API page:
    A servlet should be able to handle cases in which the client does not choose to join a session, such as when cookies are intentionally turned off. Until the client joins the session, isNew returns true. If the client chooses not to join the session, getSession will return a different session on each request, and isNew will always return true.
    Check to see if you have cookies disabled in your browser.
    ~ishnid
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    5
    Rep Power
    0

    Thanks but....


    It is so kind of you, Nemi and ishnid, that you gave me some of your time, so thank you a lot, and I wish that some day I can help in return.
    But Nemi yes I have a different session ID even if I merely tried the retry button.
    Ishnid of course I’ve checked that my browser accept all kinds of cookies.
  14. #8
  15. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,898
    Rep Power
    3887

    Re: Thanks but....


    Originally posted by Aladdin11

    Ishnid of course I’ve checked that my browser accept all kinds of cookies.
    Lol - I wan't doubting you, it's just the kind of silly error that tends to make people pull their hair out for hours.

    ~ishnid
  16. #9
  17. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    5
    Rep Power
    0
    Anyway I don't think it is relyable to use it in a real application.
    I'm I right or I just could'nt manage to use it the right way?
    Please tell me what do you think ishnid.
    thanks for caring
  18. #10
  19. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    Sessions are generally considered a reliable way of storing information across requests for users on your web site.

    If I were you I would concentrate on the server configuration. Try installing a different app server, like JRun or an older version of Tomcat, if Tomcat is what you are using.
  20. #11
  21. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,898
    Rep Power
    3887
    I'm currently running servlets on Tomcat 4.1.12 and the sessions work fine.
  22. #12
  23. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,898
    Rep Power
    3887
    I actually came across this problem myself this weekend. I was installing Tomcat at home and the session ID was different each time. The servlet classes I was compiling with were in the servlet.jar archive bundled with Tomcat 4.1.18. The server I normally use runs Tomcat 4.1.12 and it works fine. Alternatively, I downloaded J2EE 1.3.1 and included j2ee.jar in the classpath and that worked ok too.
    ~ishnid

IMN logo majestic logo threadwatch logo seochat tools logo