Thank you Rosdi and James for your help. Rosdi Sedi a écrit : > Bruno & James, > > I did understand Bruno's problem. I faced the exact same problem quite some > time ago (imagine writing a servlet for Netscape Enterprise which supports > (supposedly) only jsdk 1.0!). > > What I did (which I think much simpler than what James did, however less > secure) was having the javascript to check the existence of the cookie. If > the cookie doesn't exist, create one (with appropriate lifespan, say.. 1 > day) then have the javascript to redirect the viewer to 'new visitor page' > the url will probably looks like this: > http://the.server/servlet/myServlet?new=1 > > The servlet can then check the existence of the 'new' parameter. When the > same viewer visits my site, the javascript will notice that the cookie is > already there and redirect the viewer to: > http://the.server/servlet/myServlet?new=0 > > Oh yes!, of course someone can easily fool my servlet easily by changing the > 'new' value to 1, which will make him/her a new visitor all the time. > > ----- Original Message ----- > From: James Tuan <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Tuesday, June 08, 1999 7:58 PM > Subject: Re: cookie with jsdk1.0 ? > > > Bruno Chevalier wrote: > > > > > > Thanks Rosdi for your help. The problem is that I can't access to this > cookie in > > > > I had the same exact problem with setting cookie with jdsk1.0. I wanted > > to goto 2.0 but and servletRunner but it 2.0 required a OS upgrade that > > would not be compatible with other 3rd party software we run. > > > > So here is what I have come up with for now. I really new to java so > > there is a problem with using "StringTokenizer cookieList=null" in the > > "getCookie" member function during repeated calls. I haven't been able > > to find the member function that resets the list to the head of the > > list, so you might have to reinitialized the class for each cookie > > you want, however if you know the sequence of the cookies > > just get them in the same order. Anyhow here it is , good luck. Also I > > still have a lot of System.print for debugging purposes > > > > James Tuan > > > > // > > > *************************************************************************** > > // Usage > > // > > > *************************************************************************** > > // Setting a cookie > > myCookie cookie = new myCookie(); > > String header = "text/html "; > > header += cookie.setCookie("CUSER_ID", PersonId,null); > > header += cookie.setCookie("CEVENT_ID", "0",null); > > header += cookie.setCookie("CGIFT_ID", "0",null); > > header += cookie.setCookie("CATTENDEES_ID", "0",null); > > header += cookie.setCookie("CFAMILY_ID", "0",null); > > res.setContentType(header); > > > > > > // Getting a cookie value > > myCookie cookie = new myCookie(); > > cookie.parseCookie(req); > > String PersonId = cookie.getCookie("CUSER_ID"); > > // > > > *************************************************************************** > > // myCookie.java > > // > > > *************************************************************************** > > import java.io.*; > > import javax.servlet.*; > > import javax.servlet.http.*; > > import java.sql.*; > > import java.lang.IndexOutOfBoundsException; > > import java.util.*; > > > > public class myCookie { > > > > StringTokenizer cookieList=null ; > > > > // > > > *************************************************************************** > > public String setCookie(String cookieName, String cookieValue, String > > todate) > > { > > // todate in of the form of Fri, 31-Dec-2012 23:59:59 GMT > > > > String temp = ""; > > > > if ( todate != null ) { > > temp = "\nSet-cookie: "+ cookieName + "=" + cookieValue > > + ";expires=" + todate + "; path=/ "; > > } > > else{ > > temp = "\nSet-cookie: "+ cookieName+ "="+ cookieValue + > > "; path=/ "; > > > > } > > > > return (temp); > > } > > // > > > *************************************************************************** > > public String getCookie ( String cookieName){ > > > > try { > > if ( cookieList != null ) { > > while ( cookieList.hasMoreTokens() ){ > > StringTokenizer valuePairs = new StringTokenizer( > > cookieList.nextToken(),"=" ); > > > > String NameValue = valuePairs.nextToken(); > > > > NameValue = NameValue.trim(); > > > > if ( NameValue.compareTo(cookieName) == 0 ) { > > String value = (String) valuePairs.nextToken(); > > System.out.println(" FOUND returning = '" + value + > > "'"); > > return (value); > > } > > > > } > > } > > return (null); > > } > > catch (Exception ex ){ > > > > return(null); > > } > > > > } > > // > > > *************************************************************************** > > public void parseCookie(HttpServletRequest req) > > { > > String key; > > String value; > > > > try { > > String myCookieString = req.getHeader("Cookie"); > > System.out.println("CookieString= " + myCookieString); > > > > if ( myCookieString != null ){ > > cookieList = new StringTokenizer( myCookieString,";" ); > > } > > > > } > > catch (Exception ex) { > > ex.printStackTrace(); > > } > > } > > // > > > *************************************************************************** > > public void sendCookie( HttpServletResponse res, String > > cookieName,String cookieValue, > > String cookieExpDate) > > { > > String header = "text/html "; > > header += setCookie(cookieName, cookieValue,cookieExpDate); > > res.setContentType(header); > > } > > } > > > > > ___________________________________________________________________________ > > To unsubscribe, send email to [EMAIL PROTECTED] and include in the > body > > of the message "signoff SERVLET-INTEREST". > > > > Archives: http://archives.java.sun.com/archives/servlet-interest.html > > Resources: http://java.sun.com/products/servlet/external-resources.html > > LISTSERV Help: http://www.lsoft.com/manuals/user/user.html > > > > ___________________________________________________________________________ > To unsubscribe, send email to [EMAIL PROTECTED] and include in the body > of the message "signoff SERVLET-INTEREST". > > Archives: http://archives.java.sun.com/archives/servlet-interest.html > Resources: http://java.sun.com/products/servlet/external-resources.html > LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
begin:vcard n:Chevalier;Bruno tel;fax:(33) 1 43 46 37 38 tel;work:(33) 1 43 46 37 37 x-mozilla-html:FALSE org:Marketing Process & Networks adr:;;;;;; version:2.1 email;internet:[EMAIL PROTECTED] title:Developer of <a href="http://212.37.192.55">galeriegaultier</A> note:Developer of <a href="http://www.galeriegaultier.com">galeriegaultier.com</A><br>the web shop of Jean Paul Gaultier x-mozilla-cpt:;-14016 fn:Bruno Chevalier end:vcard