开发者

can java applets (not signed) create / read cookies?

开发者 https://www.devze.com 2022-12-15 07:36 出处:网络
I was wondering if it\'s possible 开发者_如何学Pythonto write cookies to clients from unsigned applets.Yes they can, you can use JSObject for this.

I was wondering if it's possible 开发者_如何学Pythonto write cookies to clients from unsigned applets.


Yes they can, you can use JSObject for this. Small note here, you need to add the plugin.jar from the jre/lib directory to your path in order to get this compiled.

Reading:

import netscape.javascript.JSObject;

String data = "";
String cookiename = "fooCookie";
JSObject myBrowser = JSObject.getWindow(this);
JSObject myDocument = (JSObject) myBrowser.getMember("document");

String myCookie = (String) myDocument.getMember("cookie");
if (myCookie.length() > 0) {
    String[] cookies = myCookie.split(";");
    for (String cookie : cookies) {
        int pos = cookie.indexOf("=");
        if (cookie.substring(0, pos).trim().equals(cookiename)) {
            data = cookie.substring(pos + 1);
            break;
        }
    }
}

Writing:

String data = "test";
String cookiename = "fooCookie";
JSObject win = JSObject.getWindow(this);
JSObject doc = (JSObject) win.getMember("document");
String data = cookiename + "=" + data + "; path=/; expires=Thu, 31-Dec-2019 12:00:00 GMT";
doc.setMember("cookie", data);

Don't forget to encode your data in Base64.

0

精彩评论

暂无评论...
验证码 换一张
取 消