I have a very basic question. When i use any Swing components inside my Servlet, after the execution the Tomcat server gets shut down. Whereas if i use the components inside applet and then use in the Servlet the server works fine. Can anybody explain me why does it behave like that?
Here is the code which caused the server to shutdown.
Originally posted by Sachin Dimble: .. Just comment out the testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); and it will work fine....
Sachin Dimble, If you're not familiar with servlets or don't understand the issue that the original poster is having trouble with, please say so before trying to answer their question. Wrong or misleading answers are worse than no answer at all.
Joined: Dec 07, 2005
Hey Ben cool! I know it's not possible to stick swing or awt components on servlets but if try to do same it will work but logicaly it's incorrect as these components never get delivered to client side, they are running under server jvm as an seperate frame, now if i close this frame which will lead to System.exit will kill the container jvm......shut down tomact....! Dinesh's problem was why tomcat gets shut down if he closed swing application. I was letting him think about above concept.
still if Dinesh gets mislead because of my post......I am realy SORRY.
and the reason the appserver doesn't shut down when you don't call it is that the Swing stuff will have started an event dispatcher thread which never gets killed.
As Ben says, NEVER mix Swing (or AWT, or SWT) with serverside components (Servlets, JSP, EJB, webservices, etc.). You may get lucky and get something that appears to work (especially if you only use non-visual elements of the APIs) but you're inviting trouble.