aspose file tools*
The moose likes Applets and the fly likes Help Needed in Applets....Urgent Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Help Needed in Applets....Urgent" Watch "Help Needed in Applets....Urgent" New topic
Author

Help Needed in Applets....Urgent

Neo Wills
Ranch Hand

Joined: Nov 29, 2006
Posts: 40
Hi,
I am stuck with a problem. Please help me out.

The requirement is :
I have an applet which has to run an executable which produces a .txt. The applet should use this .txt to produce its output.

I made the applet into a signed jar and ran the executable to produce the .txt . But the .txt is outside the jar file and I am not able to use it to create the result.

How do I use the .txt now?? Is the method that I am trying proper or should I use some other method?

Another doubt is, when I run the .html of the applet code (which is in the server), is it cached in the client???
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39570
    
  27
Welcome to JavaRanch.

The executable runs on the client, and the file ends up on the clien thard disk? In that case you can just use the java.io classes to access it like any local file, since the applet is signed. (The jar file is anyway on the server, and has no role in this.)

The HTML page may be cached (that depends on the browser settings), but you influence that to a degree with the HTTP headers (or http-equiv meta tags) mentioned on this page.

To get the most out of JavaRanch, we have a page on HowToAskQuestionsOnJavaRanch, particularly UseAMeaningfulSubjectLine and EaseUp.


Ping & DNS - updated with new look and Ping home screen widget
Neo Wills
Ranch Hand

Joined: Nov 29, 2006
Posts: 40
Hi,
Iam sorry about the subject line. Ill take care of it in future..
About the post, the executable is not in the client end but is in the server end and hence the .txt is also in the server end but outside the signed jar (which has the applet and is being executed).

Thanks for the reply,
Bharath
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39570
    
  27
I'm curious how the applet starts an executable on the server, but that's really immaterial to your question.

The applet can download the file from the web server, as long as it's in a publicly accessible directory. Since it's just text, it could be as simple as
Neo Wills
Ranch Hand

Joined: Nov 29, 2006
Posts: 40
The applet is in a signed jar and the directory where the jar file is has the executable as well.
The applet has been coded using Runtime exec to run the executable and produce the .txt in the server directory.
Neo Wills
Ranch Hand

Joined: Nov 29, 2006
Posts: 40
Let me explain it in a much clearer way:

There is a java applet in a signed jar in a file server. The file server also has the .html to access the applet. The directory where the .jar is present has the .exe file. (.html, .jar and .exe are in the same directory)

Now, when the client system accesses the .html in the file server, the applet is invoked which runs the .exe in the same server directory and creates the .txt file in the same server directory. But it is created outside the .jar file and hence the applet can use it to generate the result.

Thanks,
Bharath
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39570
    
  27
Well, that's what you said before, but it still doesn't explain how the applet can run an executable on the server - anything the applet runs via Runtime.exec will run on the client. So, how does the applet run something on the server? But, as I've said before, that doesn't even matter with regard to your problem. The problem as you've described it is that the applet needs to read a file on the server. My previous post explains how to do that - when you tried that approach, what problems did you encounter?
Neo Wills
Ranch Hand

Joined: Nov 29, 2006
Posts: 40
I get what you said about the file reading.. Will try it now.. But for the running of the executable, how do we determine what a client is and what a server is? If i access the .html on the file server through a remote machine via its URL, the remote machine is the client right?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24168
    
  30

The "remote machine" is the "server." The machine where the user sits with their web browser is the "client".

An applet's Java code runs on the client machine. Runtime.exec() can only execute applications on the client machine. Perhaps you've gotten this to work (sort-of) in a test environment where the client and server are the same machine; but in deployment, they'll be separate and this can't possibly work.

To run an executable on the server, you must have code that runs on the server. One possibility is a servlet. Do you know what those are? The servlet could run the executable, load the text file and send it down to the applet on the client machine.


[Jess in Action][AskingGoodQuestions]
Neo Wills
Ranch Hand

Joined: Nov 29, 2006
Posts: 40
Hi,
Yes. Thats the same mistake I made... I was working on the test environment. Now I tried it on separate machines and it did not work. So now, Ill have to use JSP right?? To run the JSP on the server, will a file server do or should it be a web server?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39570
    
  27
A file server won't do. And a web server (like Apache) will only do if it is hooked up to a servlet engine (like Tomcat) somehow. It may be easier to just use Tomcat, instead of trying to set up an Apache/Tomcat combination.
 
Consider Paul's rocket mass heater.
 
subject: Help Needed in Applets....Urgent
 
Similar Threads
Making swing app as standalone program
Applets security problem
Applets security problem
Why don't running the applet developping the JAI package?
Executable Jar File