【发布时间】:2022-12-17 18:08:52
【问题描述】:
我一直面临着通过 iframe 中的 zk 框架在 java 和 javascript 之间进行通信的问题。 简单来说,我想在当前会话中保存一个字符串并在 javascript 中访问它(甚至覆盖它)。
我的 java 行:
HttpSession session = (HttpSession)(Executions.getCurrent()).getDesktop().getSession().getNativeSession();
session.setAttribute("key","testing");
我的祖尔线:
<iframe id = "change_option" src="select_one_option.html" scrolling="no" width="700px" height="400px" > </iframe>
我在 html 文件中的 javascript 行:
var session= /SESS\w*ID=([^;]+)/i.test(document.cookie) ? RegExp.$1 : false; //finds the correct session id + desktop name?
session = session.substring(0, session.indexOf('.')); //removes desktop name and keeps just the session id in a string
//another try
console.log("Saved: " + sessionStorage.getItem("key")); //returns "Saved: null"
//another try
var username = '<%= Session["key"] =%>'
console.log ( " Variable is : " + username) //returns "<%= Session["key"] %"
由于 html 文件很大,我认为最好通过 iframe 来完成,而不是尝试在 zul 文件中重写。非常感谢任何建议。
【问题讨论】:
标签: javascript java zk zul