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

    Join Date
    Jul 2003
    Rep Power

    Session can not pass attribute values?

    I have 2 servlets, called ServletA and ServletB.

    Now I call ServletA first, and in its doPost() method, I used a session to set in an attribute ID with a string value:
    String id = "123";
    //Get the current section, create one if necessary
    HttpSession session = req.getSession(true);
    if (session == null )    
       System.out.println("session is null");	
    session.setAttribute("ID", id);
    After ServletA returns a response, then I called ServletB, and in ServletB's doPost() method, I tried to get ID value:

    // Get the current sectionHttp
    Session session = req.getSession();
    if (session == null)   
        throw new ServletException("servlet session is time out!");  String id = (String)session.getAttribute("ID"); 
    System.out.println("ID=" + id);
    But unfortunately, the print-out ID value is always null. [Note session is not null here]

    In web.xml, I set the session-timeout to be 120.

    Both servlets are in the same context.

    The important thing is that I did not call the servlet from Web Browser, instead in call these 2 servlets from an application. But I don't know whether it will affect the session.

    Any one can help tell me why ID is always null?

    And how to pass ID value between ServletA and ServletB?

  2. #2
  3. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Lincoln, NE. USA
    Rep Power
    How are you calling them from an application? A session will be started if you call these from an application, but you will not be able to access that session unless the client making the request is passing the session id to the servlet when making the request. Is your application keeping the cookie sent back from the servlet and passing that back to the servlet when making future requests?
  4. #3
  5. No Profile Picture
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Rep Power
    how are you calling a servlet from a Java application?

IMN logo majestic logo threadwatch logo seochat tools logo