aspose file tools*
The moose likes Servlets and the fly likes Can you start an application on the server by calling a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Can you start an application on the server by calling a servlet" Watch "Can you start an application on the server by calling a servlet" New topic
Author

Can you start an application on the server by calling a servlet

David Duffy
Greenhorn

Joined: Mar 24, 2003
Posts: 4
Hi All,
I am taking a java web programming class and we have an assignment to write a servelet that when called will open a gui on the server to allow anyone sitting on the server to paste text into. The text pasted in the text field will then be formatted and returned to the original callers web browser.

What I'm wondering is, is it is possible to make a call to a servlet that will cause another application (which will be a gui) to open on the server macine?

Thanks for any insight you can offer.

DLD
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Is it too late to get your money back for this class?

Seriously, the container would need to be running under a user that has access to the screen. Not typical on a Unix system. Probably wouldn't work if running as a windows service either.

Look at Runtime.exec
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Runtime.html

It allows you to call external processes from a Java program and accept that process's output.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61646
    
  67

Is it too late to get your money back for this class?


Seriously! It's hard to imagine an assignment with less applicability to real-world problems.
[ October 15, 2005: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
David Duffy
Greenhorn

Joined: Mar 24, 2003
Posts: 4
Well the problem that it solves for the Prof is one in which he has 2 systems sitting on his desktop one a mac and the other a pc. If he wants to transfer some text from the mac to the pc very quickly and easily he starts the servlet it opens a GUI on the mac pastes the text and then returns. No need to ftp or copy file or rewrite text.

I also think this is an exercise in here's what I did lets see if you can do it too.

Straying from the merits of the exercise back to the topic, I looked at the runtime link you provided Ben and added some code to my doPost to open a test app that I have with a gui but I get returned an EXCEPTION_ACCESS_VIOLATION.

here's a code snippet inside my doPost method


I'm doing all of this on my local machine with admin privelges. Is there something else I need to add to execute an app as a specified user?

Thanks for your assistance.
Eddy Lee Sin Ti
Ranch Hand

Joined: Oct 06, 2005
Posts: 135
What kind of GUI your servlet going to invoke? Must it be another external application?

Perhaps you can just develop a simple Swing-based window that serves as the input screen at the server and running within the execution context of the servlet. What you need to do then is just pass the value back from the window to stream back to the client


SCJP, SCWCD, SCJWS, IBM 700,IBM 701, IBM 704, IBM 705, CA Clarity Technical<br /> <br /><a href="http://eddyleesinti.blogspot.com" target="_blank" rel="nofollow">http://eddyleesinti.blogspot.com</a>
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Either way, it's a question of screen ownership.
Under any real, multi-user system (which includes Mac OSX) there is a good likelyhood that the user under which Tomcat is running will not be the same user under which the GUI is running.

If, for the sake of the exercise, the teacher will insure that Tomcat is started user the same user that started the GUI, either approach, might work (I think). You would have to try it.

Which version of Mac will your teacher be running?
Will you have access to that OS to build and test this app?
David Duffy
Greenhorn

Joined: Mar 24, 2003
Posts: 4
Thank you all for your assistance! I figured out the problem that I was having and Ben had it right on the money. When I looked more closely at the Tomcat service properties in windows the 'Allow service to interact with desktop' checkbox was unchecked. After I checked it I could do what I had been trying to do all along.

Thanks again for your help!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Can you start an application on the server by calling a servlet