[英]how do i do an alert response from a servlet?
I would like to do an alert confirmation when user submits a form, how do I do that? 我想在用户提交表单时做一个警报确认,我该怎么做?
I've used: 我用过:
PrintWriter out = response.getWriter();
response.setContentType("text/html");
out.println("<script type=\"text/javascript\">");
out.println("alert('form submitted!');");
out.println("</script>");
but it leaves the page blank. 但页面空白。
how do I do the alert without refreshing the background page? 如何在不刷新后台页面的情况下发出警报?
You need to use AJAX. 您需要使用AJAX。 All normal requests result in a new page being served. 所有正常请求都会导致提供新页面。
btw: alert() is a bit of a blunt tool and is not considered be part of a "good user experience". 顺便说一句:alert()有点过时了,不被认为是“良好的用户体验”的一部分。 You may want to have a modal dialog instead. 您可能需要一个模式对话框。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.