【问题标题】:problem getting value from jsp to servlet从 jsp 到 servlet 获取价值的问题
【发布时间】:2011-06-21 07:25:11
【问题描述】:

我正在尝试从父 jsp 页面获取计数值(即 1)到 servlet。 但它给出了一个错误:“opener.document.getElementById(...) is null or not an object”。 这是因为我试图在不提交表单的情况下获得价值吗? 如果有人可以提供帮助,我会很高兴。

jsp:

 <td> <input type="hidden" name="count" id="count" value="1"></td>

小服务程序:

 out.print("var oWindow = window.external.menuArguments;");
        out.println("var ctr=oWindow.opener.document.getElementById(\"count\").getAttribute(\"value\");");

【问题讨论】:

  • "count" 这个在页面中是可用的,还是在页面提交后会回来??

标签: javascript jsp servlets


【解决方案1】:

这完全取决于 oWindow 或 oWindow.opener 指向哪个页面窗口,您真的有 3 个客户端窗口对象参与此操作吗?也许它应该是:

var ctr=oWindow.document.getElementById('count').getAttribute('value');

...或者您应该提供更多有关应用程序结构的信息。例如,window.external 用于扩展 MSIE 并添加自己的上下文菜单项,这与 servlet 关系不大。

【讨论】:

  • 有一个按钮打开文件,点击后从父窗口获取文件的url 目标文件:
  • 对不起,当点击打开文件时,它会在新窗口中打开一个文件。
  • 然后,当我在该文件中选择一个短语并右键单击并说“选择为目标”控件转到我需要计数值的 servlet 页面。
  • 在这种情况下,我不知道您为什么要使用 window.external.menuArguments。直接使用window.opener即可:var ctr=window.opener.document.getElementById('count').value;
  • 试过 var ctr=window.opener.document.getElementById('count').value: 给出错误:'window.opener.document'为空或不是对象.. 但是这个函数 RetURL 返回同一个 servlet 中带有 oWindow.opener 的父页面的 url。 out.println("函数 RetURL(){"); out.println("var oWindow = window.external.menuArguments;"); out.println("var oDocument = oWindow.document;var oUrl=oDocument.URL;"); out.println("return oUrl;}");
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-03
相关资源
最近更新 更多