session creation failing in IE

Discussion in 'JSP' started by karan_736, Jan 19, 2008.

  1. karan_736

    karan_736 New Member

    Joined:
    Jan 19, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  2. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    I guess you need to have a valid session before using 'request.getSession();'
     
  3. karan_736

    karan_736 New Member

    Joined:
    Jan 19, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice