Re: cookie problem
As Andy remarked: the call request.getCookies(); should return null if there are no cookies submitted. This behaviour is specified in the JavaDocs for both the Servlet 2.2 and 2.3 specs. Tomcat 3 was in error and the behaviour has been corrected for Tomcat 4 and later. HTH, Jon Paul wrote: I hava a JSP application under Tomcat 4.1.24, jdk 1.4, running as service on win2k currently in standalone mode. The default index.jsp page checks for cookie that has not yet been set. Under Tomcat 3.x (jdk 1.2), this cookie checking does not generate an error; however, under Tomcat 4 it generates an HTTP Status 500 exception report, where the root cause is given as java.lang.NullPointerException. If i subsequently run a page which does not check for cookie, that non-cookie checking page loads fine; and then the cookie checking page loads fine without any exception report. It is only when the cookie checking page runs FIRST that error message is generated. I am uncertain if this is some sort of jsp error or some sort of Tomcat error. here is code used to check for cookie, where that cookie does not exist when this code generates error. But then again, that cookie still does not exist when this code works fine (ie, after running a jsp that does not check for cookie) - which is why i am wondering if this has something to do with Tomcat 4, or perhaps how it is configured??? Cookie[] cookies = request.getCookies(); for(int j=0; jcookies.length; j++) { cookieName = cookies[j].getName(); cookieValue = cookies[j].getValue(); if (cookieName.equals(ex)) { xx = cookieValue; // wher xx is previously defined as a String object break; } } Any and all help is more than welcome, as i am a bit stumped as to how to begin troubleshooting this. -paul lomack - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: cookie problem
thank you. That worked. -paul lomack - Original Message - From: Bodycombe, Andrew [EMAIL PROTECTED] To: 'Tomcat Users List' [EMAIL PROTECTED] Sent: Tuesday, August 12, 2003 12:14 PM Subject: RE: cookie problem The request.getCookies() will return null if no cookies were sent with the request. You should check that cookies != null before checking cookies.length -Original Message- From: Paul [mailto:[EMAIL PROTECTED] Sent: 12 August 2003 17:13 To: Tomcat Users List Subject: cookie problem I hava a JSP application under Tomcat 4.1.24, jdk 1.4, running as service on win2k currently in standalone mode. The default index.jsp page checks for cookie that has not yet been set. Under Tomcat 3.x (jdk 1.2), this cookie checking does not generate an error; however, under Tomcat 4 it generates an HTTP Status 500 exception report, where the root cause is given as java.lang.NullPointerException. If i subsequently run a page which does not check for cookie, that non-cookie checking page loads fine; and then the cookie checking page loads fine without any exception report. It is only when the cookie checking page runs FIRST that error message is generated. I am uncertain if this is some sort of jsp error or some sort of Tomcat error. here is code used to check for cookie, where that cookie does not exist when this code generates error. But then again, that cookie still does not exist when this code works fine (ie, after running a jsp that does not check for cookie) - which is why i am wondering if this has something to do with Tomcat 4, or perhaps how it is configured??? Cookie[] cookies = request.getCookies(); for(int j=0; jcookies.length; j++) { cookieName = cookies[j].getName(); cookieValue = cookies[j].getValue(); if (cookieName.equals(ex)) { xx = cookieValue; // wher xx is previously defined as a String object break; } } Any and all help is more than welcome, as i am a bit stumped as to how to begin troubleshooting this. -paul lomack - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: cookie problem
Just put one more check if(cookies.length==0) return;//OR whatever you want to do when no cookie is there.. :) -Original Message- From: Paul [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 12, 2003 9:13 AM To: Tomcat Users List Subject: cookie problem I hava a JSP application under Tomcat 4.1.24, jdk 1.4, running as service on win2k currently in standalone mode. The default index.jsp page checks for cookie that has not yet been set. Under Tomcat 3.x (jdk 1.2), this cookie checking does not generate an error; however, under Tomcat 4 it generates an HTTP Status 500 exception report, where the root cause is given as java.lang.NullPointerException. If i subsequently run a page which does not check for cookie, that non-cookie checking page loads fine; and then the cookie checking page loads fine without any exception report. It is only when the cookie checking page runs FIRST that error message is generated. I am uncertain if this is some sort of jsp error or some sort of Tomcat error. here is code used to check for cookie, where that cookie does not exist when this code generates error. But then again, that cookie still does not exist when this code works fine (ie, after running a jsp that does not check for cookie) - which is why i am wondering if this has something to do with Tomcat 4, or perhaps how it is configured??? Cookie[] cookies = request.getCookies(); for(int j=0; jcookies.length; j++) { cookieName = cookies[j].getName(); cookieValue = cookies[j].getValue(); if (cookieName.equals(ex)) { xx = cookieValue; // wher xx is previously defined as a String object break; } } Any and all help is more than welcome, as i am a bit stumped as to how to begin troubleshooting this. -paul lomack - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: cookie problem
Paul, I ran into something just like this an about went out of my mind trying to figure out what was going on. Try doing it this way instead. It works for me. -Brian Cookie[] cookies = request.getCookies(); boolean foundCookie = false; if(cookies != null) { for(int i = 0; i cookies.length; i++) { Cookie cookie = cookies[i]; if (cookie.getName().equals(email)) { foundCookie = true; session.setAttribute(email, cookie.getValue()); } } } if (!foundCookie) { response.sendRedirect(welcome.jsp); // cookie not found }else response.sendRedirect(index.jsp); // cookie found -Original Message- From: Paul [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 12, 2003 9:13 AM To: Tomcat Users List Subject: cookie problem I hava a JSP application under Tomcat 4.1.24, jdk 1.4, running as service on win2k currently in standalone mode. The default index.jsp page checks for cookie that has not yet been set. Under Tomcat 3.x (jdk 1.2), this cookie checking does not generate an error; however, under Tomcat 4 it generates an HTTP Status 500 exception report, where the root cause is given as java.lang.NullPointerException. If i subsequently run a page which does not check for cookie, that non-cookie checking page loads fine; and then the cookie checking page loads fine without any exception report. It is only when the cookie checking page runs FIRST that error message is generated. I am uncertain if this is some sort of jsp error or some sort of Tomcat error. here is code used to check for cookie, where that cookie does not exist when this code generates error. But then again, that cookie still does not exist when this code works fine (ie, after running a jsp that does not check for cookie) - which is why i am wondering if this has something to do with Tomcat 4, or perhaps how it is configured??? Cookie[] cookies = request.getCookies(); for(int j=0; jcookies.length; j++) { cookieName = cookies[j].getName(); cookieValue = cookies[j].getValue(); if (cookieName.equals(ex)) { xx = cookieValue; // wher xx is previously defined as a String object break; } } Any and all help is more than welcome, as i am a bit stumped as to how to begin troubleshooting this. -paul lomack - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: cookie problem
The request.getCookies() will return null if no cookies were sent with the request. You should check that cookies != null before checking cookies.length -Original Message- From: Paul [mailto:[EMAIL PROTECTED] Sent: 12 August 2003 17:13 To: Tomcat Users List Subject: cookie problem I hava a JSP application under Tomcat 4.1.24, jdk 1.4, running as service on win2k currently in standalone mode. The default index.jsp page checks for cookie that has not yet been set. Under Tomcat 3.x (jdk 1.2), this cookie checking does not generate an error; however, under Tomcat 4 it generates an HTTP Status 500 exception report, where the root cause is given as java.lang.NullPointerException. If i subsequently run a page which does not check for cookie, that non-cookie checking page loads fine; and then the cookie checking page loads fine without any exception report. It is only when the cookie checking page runs FIRST that error message is generated. I am uncertain if this is some sort of jsp error or some sort of Tomcat error. here is code used to check for cookie, where that cookie does not exist when this code generates error. But then again, that cookie still does not exist when this code works fine (ie, after running a jsp that does not check for cookie) - which is why i am wondering if this has something to do with Tomcat 4, or perhaps how it is configured??? Cookie[] cookies = request.getCookies(); for(int j=0; jcookies.length; j++) { cookieName = cookies[j].getName(); cookieValue = cookies[j].getValue(); if (cookieName.equals(ex)) { xx = cookieValue; // wher xx is previously defined as a String object break; } } Any and all help is more than welcome, as i am a bit stumped as to how to begin troubleshooting this. -paul lomack - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Cookie problem max age problem - Best practice to solve it
From: Jose Euclides da Silva Junior - DATAPREVRJ Subject: Cookie problem max age problem - Best practice to solve it this question is very important to me. My application works with an external authentication app ( like a plugin).When the user is logged, a browser cookie is created. The problem stays whenever the user asks for a logout process and the external app tries to kill its cookie (created before by the app), probably setting cookie's max age to 0, i guess. But TomCat doesnt know that this cookie is already killed, because it just fetch the name and value. So, i would like any tips about best practice on solving this kind of problem. Cookie exchanges fall into one of two categories: - what the server sends to the client - what the client sends back to the server Tomcat wouldn't fetch the value; the client's browser sends it. Setting the max age of a cookie to zero is the proper way to delete a cookie. When doing the deletion, are you sure that the name, domain, and path values are identical to the ones used when the cookie was initially set? -- Steve - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Cookie problem with Tomcat 4.1.24
http://nagoya.apache.org/bugzilla/buglist.cgi?resolution=INVALIDresolution=WONTFIXbugidtype=includechfieldto=Nowproduct=Tomcat+4short_desc=cookieshort_desc_type=allwordssubstrbug_file_loc_type=allwordssubstrkeywords=keywords_type=anywordsfield0-0-0=nooptype0-0-0=noopvalue0-0-0=cmdtype=doit The bug database has closed this issue many times. -Tim basebeans wrote: Hello tomcat-ians, I am getting 'InvalidArgumentException' when I add a cookie to response object using response.addCookie() in a JSP file. This error is coming when the cookie has the characters comma(,), semi-colon(;) in the value. As for Cookies 0 version, these characters are not valid. As for the latest version of cookies these are valid characters for a cookie value. The above exception is coming with Tomcat 4.1.24. but not with earlier version Tomcat 4.0.3. And the same exception was coming with tomcat 3.3 earlier. Why this is being changed with different versions of Tomcat. Is this abnormality mentioned anywhere in the Tomcat documents for 4.1.24 3.3 versions. Can anyone please tell me why this is happening. tnx Venkat Dosapati ATS TransLogic Systems 5th floor Amogh Plaza, Green Lands Hyderabad, AP-500 016, India ph : +91-40-23401795 x29 fax : +91-40-23407943 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Cookie problem with nsapi_redirector.so and netscape server 3.6
I found the problem with this configuration. The URL hostname was changing in certain cases, so the cookies were not available. Making sure the URL format is managed properly solves the problem. --- David Lewis Pershing Technology Group, 51 Monroe St. Suite 1500, Rockville, MD 20850 301-517-4909 (voice), 301-762-8604 (fax), 703-517-8004 (cell) [EMAIL PROTECTED] |-+ | | David Lewis | | || | | 04/10/2002 02:53 | | | PM | | || |-+ -| | | | To: [EMAIL PROTECTED] | | cc: | | Subject: Cookie problem with nsapi_redirector.so and netscape server 3.6 | -| Last year, there was a posting regarding problems with using Tomcat and Netscape Enterprise Server 3.6 using nsapi_redirector.so: http://w6.metronet.com/~wjm/tomcat/2000/Jun/msg00095.html I didn't see any answers in archive on this issue or for this thread relative to my problem. I am having a similar problem: One netscape webserver 3.6 SP3 instance, one Tomcat 4.0.1 instance, multiple users accessing URLs via the webserver/nsapi_connector/AJP13 get mixed-up cookies, same users accessing same Tomcat instance via HTTP connector works fine. Has anyone else seen strange cookie behavior using this configuration, and do you have a workaround? I'm using the latest nsapi_redirector.so binary available at apache.org at: http://jakarta.apache.org/builds/jakarta-tomcat-4.0/release/v4.0.3/bin/solaris6/sparc/ --- David Lewis Pershing Technology Group, 51 Monroe St. Suite 1500, Rockville, MD 20850 301-517-4909 (voice), 301-762-8604 (fax), 703-517-8004 (cell) [EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED]
RE: Cookie Problem
set your cookie age to -1 -Original Message- From: Shravan Shashikant [mailto:[EMAIL PROTECTED]] Sent: Wednesday, April 25, 2001 12:15 PM To: [EMAIL PROTECTED] Subject: Cookie Problem Hi there, I have a problem using Cookies in my servlet.I am able to create the cookie and log in but then I have an option where I ask the user if he wanst to save his password and there I write a cookie for say 9 days.But when he wnts to logut ,I execute the following code. out= response.getWriter(); HttpSession session = request.getSession(true); session.invalidate(); Cookie[] cookies = request.getCookies(); for(int i=0; i cookies.length; i++) { Cookie thisCookie = cookies[i]; String name = cookies[i].getName(); String value = cookies[i].getValue(); //out.println( + name + : + value); if (thisCookie.getName().equals(user)) { // Delete the cookie by setting its maximum age to zero //out.println( Before deleting user ); Cookie killcookie = new Cookie(user,null); //Cookie killcookie = new Cookie(user,thisCookie.getValue()); thisCookie.setMaxAge(0); cookies[i].setMaxAge(0); killcookie.setMaxAge(0); //killcookie.setPath(/); response.addCookie(killcookie); killcookie.setMaxAge(0); response.addCookie(killcookie); //merciless!!! out.println( new - After deleting user ); } } The weird thing is I am not able to deleet the cookies in IE 5 by using the above method.I can still see the cookies which I had created,in the Cookies folder.They are not deleted.I heard somewhere that it takes 4-5 mins to delete cookies in IE.But then its been a day now and I know Windows's slow but then this just takes the cake.AM I doing something wrong here(it seems to work fine with NEtscape and in other versions of IE). If you've an efficient code or mechanism on how to tackle the Logout problem which's really bugging me,do tell me. Also,if setMaxAge is not used while creating the cookie then its not written to the Cookies folder.DOes it exist only in the browser header in this case? Thanks and Regards, Shravan
Re: Cookie problem max age problem
Pratik Machchar typed the following on 05:57 PM 12/5/2000 +0530 I set a cookie with certain maxAge() say 200. now on logout I wan't to remove that cookie I set maxAge(0) then also this cookis is not removed Are you getting the cookie with request.getCookies() and changing its maxAge, or creating a new cookie with the same name? I seem to recall having a problem with IE when doing it the second way, but doing it the first way worked. Actually when I see that cookie on other page through request.getCookies(); I can get that cookie but when I try to see cookie.getMaxAge() it returns -1 There's no way for Tomcat to know what the max age was on cookies it gets from the request: The Cookie: header in the HTTP request doesn't contain this information, it only sends the name and value. The browser keeps track of the expiration and simply stops sending the Cookie: header after it passes. Kief
Re: Cookie problem max age problem
- Original Message - From: "Kief Morris" [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, December 05, 2000 8:10 PM Subject: Re: Cookie problem max age problem Pratik Machchar typed the following on 05:57 PM 12/5/2000 +0530 I set a cookie with certain maxAge() say 200. now on logout I wan't to remove that cookie I set maxAge(0) then also this cookis is not removed Are you getting the cookie with request.getCookies() and changing its maxAge, or creating a new cookie with the same name? I seem to recall having a problem with IE when doing it the second way, but doing it the first way worked. I tried both the ways same problem continues Any other solution. Actually when I see that cookie on other page through request.getCookies(); I can get that cookie but when I try to see cookie.getMaxAge() it returns -1 There's no way for Tomcat to know what the max age was on cookies it gets from the request: The Cookie: header in the HTTP request doesn't contain this information, it only sends the name and value. The browser keeps track of the expiration and simply stops sending the Cookie: header after it passes. Thanks for clearing above point Kief Thanks again Pratik