codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  losing session between servlets  Archive Import (jl) at 15:03 on Tuesday, July 08, 2003
 

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");
}


  Re: losing session between servlets  Yusairi at 00:31 on Wednesday, July 09, 2003
 

i`m not expert in servlet
suggest :
use cookies technique to store your userid session.

please refer this link to improve your code.
1. http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/Servlet-Tutorial-Cookies.html

2. http://www.javacoffeebreak.com/faq/faq0058.html

hopefully it`ll help you.
Good luck.

Yusairi: site expert
http://www.codetoad.com


  Re: losing session between servlets  Elain at 07:56 on Thursday, November 11, 2010
 

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|








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  item to item recomender system
•  Re: Database Design
•  Re: Very difficult DHTML:How to add css font class to table cells
•  Re: error
•  Re: Logout Problem
•  Re: about disable form
•  Re: open excel file in html page
•  Re: Connection Problem help needed
•  Re: Open Excel in HTML page


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2010