Java netscape.javascript.JSObject used for storing cookies

左心房为你撑大大i 提交于 2019-12-08 04:46:56

问题


I have a Java application running on the web through a Webswing server. A Webswing server translates Java to HTML5 for secure web usage.

I use netscape.javascript.JSObject to store and read cookies from the Java application.

// write
String cookie = "name=userstuff; Expires.... ";
JSObject global = JSObject.getWindow(null);
global.eval("document.cookie=" + "\"" + cookie + "\"");

//read
Object cookies= global.eval("document.cookie");

I have not found a way to store passwords in the browser password section. In Chrome the section is:

chrome://settings/passwords

Could you tell me if the mechanisms to store passwords in the passwords section is the same as the one for cookies.


回答1:


Please refer to this documentation of Credential Management API - https://whatwebcando.today/credentials.html

Using the API you can programmatically force a save password dialog to show to user, who can decide whether to save the password. The API is currently supported only in Chrome.

Basically this API has nothing to do with Webswing, anyway you should be able to use the Credential Management API same way you use netscape.javascript.JSObject to work with cookies. Try this, it worked for me with Webswing:

global.eval("navigator.credentials.store(new PasswordCredential({id: 'username@email.com', password: 'password', name: 'User Name'}));");


来源:https://stackoverflow.com/questions/56771069/java-netscape-javascript-jsobject-used-for-storing-cookies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!