session creation failing in IE

karan_736's Avatar, Join Date: Jan 2008
Newbie Member
i have a small application which checks for username and
password and forwards the users to
restricted pages on confirmation. i ve uploaded the application on eatj.com for testing, now my problem is that
the session creation code is not working in Internet Explorer.means every time i refresh the page or go to some
other page, session id changes. But it is working perfect in other (Firefox, opera and netscape ) browsers. my
cookies are enabled and the code is working fine in my
development machine with I E. More over i ve tested this program on atleast 10 different machines with the same results so cookies being turned off is out of question. Any guesses what cud be wrong. cud it be some problem
in the eatj.com site.
here is my code

Code:
public class Login extends HttpServlet
{

	public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException
	{
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		if(username.equals("admin")&&password.equals("admin"))
		{
			HttpSession session = request.getSession();
			System.out.println("session id "+session.getId());
			session.setAttribute("username", username);
			RequestDispatcher dispatch = request.getRequestDispatcher("Welcome.jsp");
			dispatch.forward(request, response);			
		}
		else
		{
			response.sendRedirect("index.jsp");
		}
	}

}
It just check for the hardcoded username and password and forwards the 'admin' user to welcome.jsp page where i am printing the session id and the username with welcome message. That id stays same for all the browsers except Internet Explorer, as when i refresh the page in IE i get a new session id.
pradeep's Avatar, Join Date: Apr 2005
Team Leader
I guess you need to have a valid session before using 'request.getSession();'
karan_736's Avatar, Join Date: Jan 2008
Newbie Member
Quote:
Originally Posted by pradeep
I guess you need to have a valid session before using 'request.getSession();'
This method works like
Code:
request.getSession(true);
, so if there is no session available it will create a new session for you.
and moreover the same code is working in all the other browsers. The problem is that some how cookies set by eatj.com are not received by IE, but i wonder what is the reason.