Jump to content

session creation failing in IE

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
karan_736

karan_736

    Newbie

  • Members
  • Pip
  • 3 posts
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

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 checks 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
Arkie

Arkie

    Learning Programmer

  • Members
  • PipPipPip
  • 92 posts
If you've tested this on 10 different machines with the same results did you ever think it could be because if IE?

#3
karan_736

karan_736

    Newbie

  • Members
  • Pip
  • 3 posts

Arkie said:

If you've tested this on 10 different machines with the same results did you ever think it could be because if IE?

It is dear. it is because of IE. but my question is why? this is a very simple program, am not using any plug in etc, so this is just a simple case of accepting cookies and creating a session, as all the other browsers are doing, But not the IE. why IE is not accepting cookies from the eatj.com. I ve tried to put the site in the trusted sites area of my IE, but no effect.

#4
bcoe

bcoe

    Newbie

  • Members
  • Pip
  • 4 posts
I've had trouble with sessions in servelets,

I would recommend using cookies instead, I know for a fact this will work in IE, Firefox and any other major browser -- a user pretty much expects to get cookies from most websites nowadays, so I don't really think there is the stigma attached to them that there once was...

Let me know if you want any sample code

Cheers,

Ben.

#5
karan_736

karan_736

    Newbie

  • Members
  • Pip
  • 3 posts
bcoe , thanks for reply. I think by default session handling in servlet api is done through cookies only, if cookies are disabled only then url rewriting comes to play. But the thing here is that IE is not accepting cookies from that particular site, even if i am managing my cookies manually, means i am writing my own cookies and setting those in the response. this is the most weired thing i ve seen.