July 12th, 2003, 02:30 PM
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:
After ServletA returns a response, then I called ServletB, and in ServletB's doPost() method, I tried to get ID 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");
But unfortunately, the print-out ID value is always null. [Note session is not null here]
// 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);
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?
July 13th, 2003, 04:04 PM
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?
July 14th, 2003, 02:27 AM
how are you calling a servlet from a Java application?