Two Laptop Bag*
The moose likes Applets and the fly likes Access Server File from Applet without Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Access Server File from Applet without Tomcat" Watch "Access Server File from Applet without Tomcat" New topic
Author

Access Server File from Applet without Tomcat

Bd Howard
Greenhorn
Ranch Hand

Joined: Mar 30, 2012
Posts: 80
Hello,

Is it possible to grab a file stored on the server without using Tomcat?

I have been tasked with parsing and displaying a log file inside a legacy Applet. Both the Applet and the log file are stored on the same server. As I am reading up on this, I have discovered that JSch may be the way to go. That said, Tomcat is not installed on the server and the powers that be don't want to "mess" with that server.

Could someone point me in the right direction as to how I might grab a file (with this Tomcat restriction) so I can display it in the Applet? I can do everything involved with this task except get the file.

I can ssh into the server from the client.

Appreciate the help

BD


I've got just enough Java knowledge to royally screw everything up. :-)
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Probably you can. You don't need Tomcat to do that, you just need an ordinary web server which will serve that file to the outside world. You're already running a server to support the applet, right? So configuring that server to serve the file would work fine.

Once you get the configuration done, the first test is to see whether a browser can access the file. If it can, then the applet should be able to access it as well.
Bd Howard
Greenhorn
Ranch Hand

Joined: Mar 30, 2012
Posts: 80
I appreciate the response Paul.

Today I explored grabbing the file via PHP and that worked well. I now have the contents displaying in the browser after parsing it with PHP.

I can get the file onto the client easily from outside the Applet, but I need it passed (or the parsed contents of the file passed) into the Applet. Also, the specific file is chosen via JComboBox in the Applet so that variable must be sent to the server.

Anyway, the PHP seems to be working but I'll take your advice and look into having IT configure the server so the log directory is served to the outside world. I don't expect that to be a problem since this is an intranet and the "world" is kinda small.

Thanks again Paul,

BD

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
See http://www.coderanch.com/how-to/java/CodeBarnApplets for some example applets that access files on a server, specifically LoadAGif and HelloServerFile.


Ping & DNS - my free Android networking tools app
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

To access the file from the applet, you first need to know its URL, i.e. the URL via which the browser can download it. Then use the applet's getDocumentBase() method to get the URL of the page in which the applet is embedded, and work from there (via a relative path) to get the URL of the file. Then the URL has an openStream() method which gives you an InputStream to read the file from.
Bd Howard
Greenhorn
Ranch Hand

Joined: Mar 30, 2012
Posts: 80
Ulf & Paul,

These two breadcrumbs you've given me are exactly what I was looking for. Now I have a trail to follow and implement.

Many thanks

BD
 
 
subject: Access Server File from Applet without Tomcat