java 关闭jsp窗口

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3854088/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 03:41:39  来源:igfitidea点击:

closing jsp window

javajspservlets

提问by yonatan

i have a jsp page that checks a query if the answer is true the program goes to a servlet page otherwise the program continue as planned my question is: if i do go to the servlet page how can i close the original jsp page from the servlet

我有一个检查查询的 jsp 页面,如果答案为真,程序会转到 servlet 页面,否则程序会按计划继续我的问题是:如果我确实转到 servlet 页面,如何从 servlet 中关闭原始的 jsp 页面

回答by Jigar Joshi

you can do it using javascript, and make them execute when your condition satisfy

您可以使用javascript来完成,并在您的条件满足时让它们执行

回答by Andriy Sholokh

You can not close browser window from the servlet.

您不能从 servlet 关闭浏览器窗口。

But you can close window using javascript.

但是您可以使用 javascript 关闭窗口。

For example write something like:

例如写这样的东西:

<body onLoad="closeWindow(<% bean.isCloseWindow %>)">

And in javascript function "closeWindow" do something like this:

在 javascript 函数“closeWindow”中做这样的事情:

function closeWindow(ifClose) {
if (ifClose) {
window.close();
}
}

回答by BalusC

It's true that you can close a window using JavaScript's window.close(), but the window will only be closed when the window is opened by yourapplication using window.open()and notwhen it is opened by the enduser itself (e.g. by a link, form submit, bookmark, etc).

确实,您可以使用 JavaScript 关闭窗口window.close(),但是只有在您的应用程序使用打开窗口时才会关闭窗口,window.open()不会在最终用户本身打开窗口时关闭(例如,通过链接、表单提交、书签等) .