我想知道是否可以从未签名的applet向客户端写cookie.
解决方法
是的,他们可以,你可以使用JSObject.
小编在这里,您需要将jre / lib目录中的plugin.jar添加到您的路径中以便进行编译.
小编在这里,您需要将jre / lib目录中的plugin.jar添加到您的路径中以便进行编译.
读:
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);
不要忘记在Base64中对数据进行编码.