Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Topics

Recent Status Updates

View All Updates

Photo
- - - - -

session creation failing in IE

session

  • Please log in to reply
4 replies to this topic

#1 karan_736

karan_736

    CC Lurker

  • Just Joined
  • Pip
  • 3 posts

Posted 18 January 2008 - 09:49 PM

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.
  • 0

#2 Arkie

Arkie

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 90 posts

Posted 22 January 2008 - 11:19 AM

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

#3 karan_736

karan_736

    CC Lurker

  • Just Joined
  • Pip
  • 3 posts

Posted 23 January 2008 - 12:06 AM

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.
  • 0

#4 bcoe

bcoe

    CC Lurker

  • Just Joined
  • Pip
  • 4 posts

Posted 25 January 2008 - 06:07 PM

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.
  • 0

#5 karan_736

karan_736

    CC Lurker

  • Just Joined
  • Pip
  • 3 posts

Posted 25 January 2008 - 08:50 PM

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.
  • 0





Also tagged with one or more of these keywords: session

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download