Go4Expert

Go4Expert (http://www.go4expert.com/)
-   JSP (http://www.go4expert.com/forums/jsp/)
-   -   session creation failing in IE (http://www.go4expert.com/forums/session-creation-failing-ie-t8335/)

karan_736 19Jan2008 11:02

session creation failing in IE
 
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 19Jan2008 16:05

Re: session creation failing in IE
 
I guess you need to have a valid session before using 'request.getSession();'

karan_736 19Jan2008 19:56

Re: session creation failing in IE
 
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.


All times are GMT +5.5. The time now is 04:35.