I know this is a weird question. I am working on a web application where the welcome-file is a servlet (which collects data from database) and forward to JSP. When I read cookies in the Main servlet, FireFox shows me File not found error, Safari opens a popup to save a file named as "www.mydomain.co.uk", Internet Explorer closes automatically

And when I read the cookies in JSP scriplet as follows,

//Read cookies and check if log in info is correct
    Cookie[] cookies = request.getCookies();
    for(int i = 0; i < cookies.length; i++)
    { 
        Cookie c = cookies[i];
        if (c.getName().equals("__iaqwc"))
        {
            if(!c.getValue().equals(""))
            {
                info = c.getValue();
            }
        }
    }

It does not read cookies first time and does not show anything on the page (which I am generating usnig javascript), and when I refresh the page then is shows me the stuff and reads cookies. I am reading cookies inside the "head tag" and this is happening only for main page other pages are working fine. And Also works fine on the local server but when I upload on the live server the said problem occurs.

Any Idea what could be the problem.

Thanks

有帮助吗?

解决方案

On first request, the returned value of request.getCookies() might be null.

 Cookie[] cookies = request.getCookies();
 if(cookies!=null) {
    //code here
 }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top