Solved

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

Posted on 2004-04-22
7
301 Views
Last Modified: 2008-03-10
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
Comment
Question by:nixj14
7 Comments
 
LVL 27

Assisted Solution

by:rrz
rrz earned 66 total points
ID: 10895694
>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
 
LVL 1

Author Comment

by:nixj14
ID: 10895766
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
 
LVL 7

Assisted Solution

by:searlas
searlas earned 66 total points
ID: 10897400
Are you using SSL in your development environment?  If not, it may work if you remove the setSecure method.
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 1

Author Comment

by:nixj14
ID: 10898370
Yes, environment is run over SSL.
0
 
LVL 1

Author Comment

by:nixj14
ID: 10899328
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
 
LVL 4

Accepted Solution

by:
indigostark earned 68 total points
ID: 10938258
try the following:
userCookie.setDomain( COOKIE_DOMAIN );

Where COOKIE_DOMAIN is a string representation of your website / network domain
(ie)
"*.mywebsite.com"
0
 
LVL 1

Author Comment

by:nixj14
ID: 10938941
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Employees depend heavily on their PCs, and new threats like ransomware make it even more critical to protect their important data.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question