简体   繁体   English

如何从Servlet发出警报响应?

[英]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.

相关问题 如何将响应从servlet转换为字符串? - How do I convert a response from a servlet to a String? 如何停止Safari缓存Servlet响应? - How do I stop Safari from caching my Servlet response? 如何从java servlet中的chunked响应中发送Http预告片/页脚? - How do I send Http trailers/footers in a chunked response from within a java servlet? 如何防止servlet在响应中转义双引号 - How do I prevent the servlet from escaping the double quotes inside a response 我想在用户输入错误密码后发出警报(验证来自数据库),我需要从Servlet生成警报,该怎么做? - I want throw an alert after the user enters wrong password (the validation is from DB), I need to generate alert from my Servlet, how to do that? 链接链接不会触发Servlet,而Servlet没有响应 - Clinking link do not trigger Servlet no response from servlet 如何从javax.servlet.filter doFilter方法返回JSON响应消息和HTTP错误代码? - How do I return a JSON response message and an HTTP error code from javax.servlet.filter doFilter method? 如何从servlet中获取其他servlet的URL - How do I get URLs of other servlets from within a servlet 如何从 Java servlet 中抛出 404 错误? - How do I throw a 404 error from within a java servlet? 如何在不离开页面的情况下从servlet返回字符串? - How do I return a string from a servlet without leaving the page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM