Why is the JasperViewer closing my Tomcat server?

I'm a little embarrassed to write this article, but many similar questions posted on the JasperReports forums indicate that this might be very useful to some people out-there.

First of all, if you experience this, it means we are talking about a Web application. The JasperViewer is a Swing based desktop application. So the first thing you should ask yourself is: "How should I expect a desktop Swing client application to work within a Web server?"

If you did not ask yourself this yet, then please take your Web application and deploy it on a different computer and try to access it using a browser from your computer. What do you see when you get to the point where the JasperViewer should pop-up? Do you see it opening up on your computer, which is the client machine? Of course not! You see it being open on the other machine, which is now the server.

While you were working with the Web server on your computer, everything went well, because you probably did not realize that your machine acted both as a server and as a client at the same time.

I will not attempt to explain more about what client/server architecture is and how Web applications are supposed to work. There are better people and books that explain this and I recommend you look for them and read them.

I will only say that if you want to display reports using the Swing viewer inside a Web application, than the Swing viewer should be deployed as a Java applet and not called directly from within server-side code. Please take a look at the /demo/samples/webapp sample provided with the JasperReports project package and see how we make use there of the jasperreports-xxx-applet.jar to display reports in Web environment.

The FAQ here explains why applications exit when the JasperViewer is closed.



I have the same problem
Any sugess??