可Java小程序(未签名)创建/读取cookie吗? [英] can java applets (not signed) create / read cookies?
本文介绍了可Java小程序(未签名)创建/读取cookie吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否有可能从未签名的Applet写饼干给客户。
I was wondering if it's possible to write cookies to clients from unsigned applets.
推荐答案
是的,他们可以,你可以使用JSObject这一点。
在这里小记,你需要从jre / lib目录中plugin.jar添加到您的路径为了得到这个编译。
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.
阅读:
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;
}
}
}
写作:
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);
不要忘了EN code为Base64您的数据。
Don't forget to encode your data in Base64.
这篇关于可Java小程序(未签名)创建/读取cookie吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文