Solved

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

Posted on 2004-04-22
7
303 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
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!

 
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

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
xjc and jaxb 2 95
Fisheye tool 2 121
Can't access image with tomcat/html 6 106
by zero exception 10 69
After-hours service is a fact of life for most MSPs. While not the most pleasant aspect of the job, there are ways to make after-hours servicing a more profitable and organized enterprise.
Arrow Electronics was searching for a KVM  (Keyboard/Video/Mouse) switch that could display on one single monitor the current status of all units being tested on the rack.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

735 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