Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-04-22
7
Medium Priority
?
306 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 28

Assisted Solution

by:rrz
rrz earned 132 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 132 total points
ID: 10897400
Are you using SSL in your development environment?  If not, it may work if you remove the setSecure method.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 136 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Read on to get a few ideas on how to promote your next corporate event.
While opting for any web-to-print solution, you need to discuss with your team and some of your end users and know their opinions about your decisions. In this article we list down some questions you need to ask yourself.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

715 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