JasperViewer
is a swing component it is launched on the computer that executes the command (normally used in installed applications), hence if you execute the command on server it will open on server (or throw a HeadlessException
, if not configured to have a screen), conclusion we can't use this command in our server application.
You could use an applet to launch the command on client computer but I strongly recommend not to use this (its support in browser is decreasing, so you can't be sure that it's working for all clients)
Normally what is done instead is that an export to pdf (html or other format of choice) is sent to client browser, client can open file with favorite program and preview it.
In your example code you are already exporting to pdf, pass the pdf directly to client. Hence remove
JasperViewer.viewReport(print, false);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…