Search This Blog

Total Pageviews

Sample code to get Cookies of Client Browser using JSP/Applet

Try the following code to get the client browser cookies by using JSP/APPLET.

JSObject is required. Please download netscape jars from netscape.

import netscape.javascript.JSObject;
import netscape.javascript.JSException;
public String getCookies() { /* ** get all cookies for a document */
try {
JSObject myBrowser = (JSObject) JSObject.getWindow(this);
if (myBrowser==null) { System.err.println("## HackApplet.getCookies() No Window"); return ""; }
JSObject myDocument = (JSObject) myBrowser.getMember("document");
if (myDocument==null) { System.err.println("## HackApplet.getCookies() No Document"); return ""; }
String myCookie = (String)myDocument.getMember("cookie");
if (myCookie==null) { System.err.println("## HackApplet.getCookies() No Cookie"); return ""; }
if (myCookie.length() > 0)
return myCookie;
catch (JSException e){
System.err.println("HackApplet.getCookies(): "+e.getMessage());
Throwable t = (Throwable)e.getWrappedException();
System.err.println(" "+t.getMessage());
return "?";
public String getCookie(String name) {
String myCookie = getCookies();
String search = name + "=";
int offset = myCookie.indexOf(search);
if (offset != -1) {
offset += search.length();
int end = myCookie.indexOf(";", offset);
if (end == -1) end = myCookie.length();
return myCookie.substring(offset,end);
return "";

No comments:

gradlew : The term 'gradlew' is not recognized as the name of a cmdlet, function, script file , or operable program

The command gradlew was not found, but does exist in the current location.  Windows PowerShell does not load commands from the current locat...