Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 307
  • Last Modified:

Passing a cookie from 1 JSP page to another works in Netscape but not in IE

I've run into an acute annoying scenario that seems to occur on select environments only (my development environment in this case).  In my scenario, I create and add several cookies to the response object within my JSP page, and then redirect on to the next JSP page.  The 2nd JSP page checks to make sure that those cookies are on the request before it continues on.  For some reason (because this same code works in our production environment) it doesn't seem to pass along the cookie in my development environment when using IE as my browser.  BUT, and this is a very odd but, when accessing the same site using Netscape, it works...  This has stumped me for a few weeks now, so I thought I'd get some outside thought on the matter.

Here's my environment:
JDK 1.4.1_06
Tomcat 4.1.27
Windows 2000

Here's a snippet of the 1st page:
//____________________________________________
Cookie userCookie = new Cookie("UserName", username);
userCookie.setPath("/");
userCookie.setSecure(true);
userCookie.setMaxAge(-1);
response.addCookie(userCookie);
response.sendRedirect("Home.jsp");
//____________________________________________
Here's the beginning snippet of the Home.jsp:
//____________________________________________
Cookie[] cookies = request.getCookies();
if (cookies == null)
   System.out.println("No cookies");//this always happens in IE
for (int i = 0; i < cookies.length; i++)
{
   if (cookies[i].getName().equals("UserName"))
   {
      user = cookies[i].getValue();
      System.out.println("User=" + user);
      break;
   }
}
0
nixj14
Asked:
nixj14
3 Solutions
 
rrzCommented:
>userCookie.setMaxAge(-1);
Doesn't  the  -1  cause the cookie not to be stored ?
>response.sendRedirect("Home.jsp");
This tells the browser to make a new request.

What are you putting in the cookies ?
Could you use session objects instead ?
rrz
0
 
nixj14Author Commented:
Sessions are not an option currently.  As for the -1, it simply means that the cookie is not persisted after the browser is closed, which is the functionality that we are looking for.  The sendRedirect command simply sends a redirect response back to the client browser, directing them to the Home.jsp page.
0
 
searlasCommented:
Are you using SSL in your development environment?  If not, it may work if you remove the setSecure method.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
nixj14Author Commented:
Yes, environment is run over SSL.
0
 
nixj14Author Commented:
Here's another interesting twist.  WHen I reference my machine as "localhost", everything works in both Netscape and IE.  It is when I reference my computer by its computer name that I'm getting the failure in IE.
0
 
indigostarkCommented:
try the following:
userCookie.setDomain( COOKIE_DOMAIN );

Where COOKIE_DOMAIN is a string representation of your website / network domain
(ie)
"*.mywebsite.com"
0
 
nixj14Author Commented:
indigostark, I tried that as well.  I've actually resolved this issue myself.  I'm going to have to tip my hat to microsoft on this one.  My college suggested that I try renaming my computer to see what happens, and it turns out that my problems went away.  I tried renaming my computer back to see if it was a fluke, and it still did not work.  Before that I tried checked DNS settings, cleared all cache information, and nothing seemed to work, but the changing of my computer name.

I found the solution but never found the cause, so I guess I'll split the points to everyone.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now