How can an Applet write/read a cookie for the user's browser without using the JSObject class?

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(
  "NameOfTheCookie","Data For the Cookie");
boolean bGetCookie = InternetGetCookie(
[FAQ Manager note - with standard Java, you can't.]
0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.