|
Hi,
I have a logon servlet, which creates a new session if necessary and sets the session userId. If a user logs on with a valid username/password, I flow to a second servlet.
The problem is that I lose the session going from the first servlet to the second. The session is definitely being set in the first servlet, but returns null in the second servlet. Any help you could provide would be greatly appreciated.
Some code snippets follow:
------------------------------------------------------------------UserServlet
------------------------------------------------------------------
HttpSession session = req.getSession(true);
String currentUserId = (String) session.getAttribute("userId");
if (currentUserId != null) {
if (!currentUserId.equals(userId)) {
session.invalidate();
session = req.getSession();
}
}
session.setAttribute("userId", userId);
... Validate the login ...
... if login is valid -->
RequestDispatcher rd = req.getRequestDispatcher("StockWatchServlet");
rd.include(req, resp);
------------------------------------------------------------------
second Servlet
------------------------------------------------------------------
if (session != null) {
System.out.println("session is NOT null");
String userId = (String) session.getAttribute("userId");
}
else {
System.out.println("session IS null");
}
|
|
|
|
|
I'm sorry i can't help to solve this problom, but i will ask my friends about it and tell you the answer!
---------------------------------------------- flash banner|logo maker|flash menu|
|
|
|
|
|
|
|
|