简体   繁体   English

尝试显示消息框时,NetBeans IDE 6.9.1中的Glassfish服务器停止工作

[英]The Glassfish Server in NetBeans IDE 6.9.1 stopped working when an attempt was made to display a message box

I'm working with JSF web applications. 我正在使用JSF Web应用程序。 Since Java doesn't support a direct way to display a message box in web applications, I decided to try something new and thought that the methods which are used to display a message box in conventional desktop applications should be tried out. 由于Java不支持在Web应用程序中显示消息框的直接方法,因此我决定尝试一些新方法,并认为应该尝试使用传统的桌面应用程序中显示消息框的方法。 For the sake of simplicity, I have tried the following method in Java Servlet. 为了简单起见,我在Java Servlet中尝试了以下方法

JOptionPane.showMessageDialog(null, "A message from Java Servlet.");

without expecting that it would work but it indeed worked and a message appeared on the web browser! 没想到它会起作用,但确实起作用,并且在网络浏览器中出现一条消息! I felt that I had found something new but also found that the Glassfish server in my NetBeans 6.9.1 had stopped working in two or three attempts. 我觉得自己发现了一些新东西,但也发现我的NetBeans 6.9.1中的Glassfish服务器已停止工作了两到三次。 It turned off with no warning , no error and no exception at all! 它关闭时没有警告,没有错误,也没有异常!


The screen shot can be seen below. 屏幕截图如下所示。 Servlet显示的消息


Now, if the use of this method in Java web is illegal, it should not be allowed to use this method at all in Java web and some errors or exceptions should be raised when an attempt is made to do so. 现在,如果在Java Web中使用此方法是非法的,则不应完全允许在Java Web中使用此方法,并且在尝试这样做时会引发一些错误或异常。 It should be a compile-time error and if it is so then, how did the message appear through Java Servlet on the web browser? 这应该是编译时错误,如果是,那么该消息如何通过Web浏览器上的Java Servlet出现? and also, Why did the Glassfish server stop working? 而且,为什么Glassfish服务器停止工作?

I have no idea why Glassfish stopped, I guess that it's been caused by dangling Swing/AWT threads in the background. 我不知道为什么Glassfish停止了,我想这是由后台悬挂的Swing / AWT线程引起的。 It has always been an extremely bad idea to manually spawn (unmanaged) threads in a lifelong running Java EE webapplication. 在终生运行的Java EE Web应用程序中手动生成(非托管)线程一直是一个非常糟糕的主意。 Once the request finishes, you loses the control. 请求完成后,您将失去控制。 You'd have to collect references to the threads in the session or application scope, preferably in a pool which get properly cleaned up on session or application destroy/shutdown. 您必须收集对会话或应用程序范围内线程的引用,最好是在一个池中,这些线程在会话或应用程序销毁/关闭时得到了适当的清理。

But that message is actually not displayed by the webbowser, but by the webserver. 但是该消息实际上不是由Webbowser显示,而是由Web服务器显示。 This means that your intention will only work when both the webserver and webbrowser runs at physically the same machine. 这意味着只有当Web服务器和Web浏览器都在同一台计算机上运行时,您的意图才会起作用。 This does obviously not happen when you publish your website into a production environment on the world wide web which get visited by clients using physically different machines. 当您将网站发布到万维网上的生产环境中时,客户使用物理上不同的机器进行访问时,显然不会发生这种情况。

All the webbrowser retrieves and executes is just plain HTML/CSS/JavaScript. Web浏览器检索和执行的所有内容只是纯HTML / CSS / JavaScript。 In JSF, you need JavaScript's alert() , confirm() , etc or just some absolutely positioned <div> in an overlay if you want a more fine grained control over the markup and look'n'feel and/or executing managed bean actions. 在JSF中,如果您希望对标记进行更细粒度的控制,并且看起来和/或执行托管Bean操作,则需要JavaScript的alert()confirm()等或仅在覆盖中绝对定位的<div> The latter is available in flavor of a single JSF component by a lot of 3rd party component libraries, such as PrimeFaces with <p:dialog> and <p:confirmDialog> and RichFaces with <rich:popupPanel> . 后者可以通过许多第三方组件库以单个JSF组件的形式使用,例如带有<p:dialog><p:confirmDialog> PrimeFaces和带有<rich:popupPanel> RichFaces

If you really need to run Swing/AWT in a web application for some reason, then you should rather be creating an applet instead and ultimately embed it in your web page by HTML <applet> or <object> tag. 如果由于某种原因确实需要在Web应用程序中运行Swing / AWT,则应该改为创建一个applet,并最终通过HTML <applet><object>标记将其嵌入到您的网页中。 This will be downloaded from the server to the client and executed in the client's environment. 这将从服务器下载到客户端,并在客户端环境中执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM