aspose file tools*
The moose likes Servlets and the fly likes Calling a GUI application from Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Calling a GUI application from Servlet" Watch "Calling a GUI application from Servlet" New topic
Author

Calling a GUI application from Servlet

Dhandapani Venkataraman
Greenhorn

Joined: Nov 30, 2003
Posts: 10
Hi,

I need to call a GUI application(not an applet) from a servlet. Can somebody exlain me how it can be done?
Thanks in advance.
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
Do you mean a GUI on the server side or on the client side?
Atul Prabhu
Ranch Hand

Joined: Dec 17, 2002
Posts: 60
Hi,

I have never tried it. But you can definitly try

Runtime rt = System.getRuntime();
rt.exec("java MainClass"); // MainClass which loads the GUI


Regards
Atul
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
I think the question here is "why" do you need to call a GUI application from a servlet? Does it write out some file that you need to relay to the client or something?


James Carman, President<br />Carman Consulting, Inc.
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
You could try to launch a GUI on the server but this will most likely fail.
Many servers don't have videohardware installed in which case Swing and AWT will throw a fit.
Even if there is videohardware installed, there is most likely noone to interact with the GUI.
And what will you do if there's multiple requests coming in, each of which tries to launch that GUI?
It could quickly become a mess for the poor soul you've drafted to use all those started applications.


42
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I need to call a GUI application(not an applet) from a servlet. Can somebody exlain me how it can be done?
Thanks in advance.


Can you take a little more time to explain what it is that you want to do?
There are several different ways to get Java apps to talk to one another. The best one depends on your requirements.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
Originally posted by Jeroen Wenting:
You could try to launch a GUI on the server but this will most likely fail.
Many servers don't have videohardware installed in which case Swing and AWT will throw a fit.
Even if there is videohardware installed, there is most likely noone to interact with the GUI.
And what will you do if there's multiple requests coming in, each of which tries to launch that GUI?
It could quickly become a mess for the poor soul you've drafted to use all those started applications.


Swing applications can be run "headless" now, so you don't need something like Xvfb (X Virtual Frame Buffer) to "mock" a graphics environment. That isn't to say that running a graphical application during a request is a good idea.
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
maybe they can in some circumstances, but can they be run headless when there's a screen that a user needs to type something into?

Kinda hard to have a headless application if that application is waiting for input that never arrives because there's no screen to enter it into (or there is a screen but no person to look at it).
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
Good point! :-) But, I only brought up the headless option because I have written webapps that needed to use the AWT/Swing classes to "paint" and the imageio package classes to return the dynamically generated images. Maybe that's what they're doing and that's what they meant by "gui application"? Who knows. I would hope that they aren't actually trying to popup a screen for someone to input something as part of the request. There are better ways to do something like that.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Calling a GUI application from Servlet