Solved

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

Posted on 2004-04-22
7
300 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
ajax auto save 15 93
maven project import to eclipse problems 13 94
jersey maven project error 7 134
struts hibernate integration example 28 113
In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
A Short Story about the Best File Recovery Software – Acronis True Image 2017
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now