How can an Applet write/read a cookie for the user's browser without using the JSObject class?
Created May 4, 2012
Davanum Srinivas If you are using Internet Explorer, J/Direct can be used to access cookies. Here are the definitions for the native entrypoints.
/** @dll.import("WININET") */ static native boolean InternetGetCookie( String lpszUrl, String lpszCookie, StringBuffer lpBuffer, int lpdwBufferLength[]); /** @dll.import("WININET") */ static native boolean InternetSetCookie( String lpszUrl, String lpszCookie, String lpszCookieData);
The usage is as follows:
int len[] = new int[] {1024}; StringBuffer buf = new StringBuffer(len[0]); boolean bSetCookie = InternetSetCookie( "http://url.for.the.cookie", "NameOfTheCookie","Data For the Cookie"); boolean bGetCookie = InternetGetCookie( "http://url.for.the.cookie", "NameOfTheCookie",buf,len);[FAQ Manager note - with standard Java, you can't.]