Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 12th, 2007, 10:22 PM
nosale nosale is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2007
Posts: 110 nosale User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 23 m 10 sec
Reputation Power: 2
Applet File Access on Server

Hello,

I am developing a time series forecaster in java. Ideally, I want it to run client side as a Java applet. In this applet, I need to load data from an external file. Is there a way an applet can open files for reading that are on the server that the applet was downloaded from? I have not tried it yet, but I believe this violates Java's sandbox (heaven forbid I start doing applet signing, certificates, etc...). I know I can write a server that the applet will connect to and download the data, but that seems like too much trouble (plus my Linux box just died so I don't have my own server anymore). Anybody know if it's possible?

Summary: I need to know if I can open and read files with an applet - the applet and file I need to open are both on the same server.

Thanks in advance for any help!

EZ-E

<edit>
Well... I tried to sleep, and I couldn't think of anything but this problem since it pretty much stops my research dead in it's tracks. Anyways, somehow this solution popped into my head and seems to serve the purpose. I'll post it here in case anybody else needs it... or there is something wrong with what I'm doing (somebody will correct me right? ):

As long as the applet source is from the same place (server) as the data file, you can (if the source is not the same as the server, it will generate a security exception) do this:

Code:
URL dataStream = new URL("http://someURLWhereYourAppletIs/dataFileName");
BufferedReader in = new BufferedReader(new InputStreamReader(dataStream.openStream()));

String str;
while((str = in.readLine()) != null) {
  //... do your processing in here
}

Is it a too simple solution to be true? I've tested it already and it seems to work. Guess this kinda circumvents the sandbox (through a degree of separation) since the page that you access via the URL class can be a php, asp, etc. script which, in turn, can access any page/read write any files (on the server) that it wants to. Haven't seen anything on the web about this, so I thought I'd post it! All this may be common knowledge to you Java programmers (I'm still learnin'!), but it's definitely valuable knowledge for me... sorry for bein a noob Thanks to whoever read this!
</edit>

Last edited by nosale : June 13th, 2007 at 06:55 AM. Reason: Figured it out

Reply With Quote
  #2  
Old August 8th, 2007, 02:38 AM
tmr28prn tmr28prn is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 1 tmr28prn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 50 sec
Reputation Power: 0
Hi i hope u can use file input stream reader instead of input stream reader alone(Java I/O package)
Quote:
Originally Posted by nosale
Hello,

I am developing a time series forecaster in java. Ideally, I want it to run client side as a Java applet. In this applet, I need to load data from an external file. Is there a way an applet can open files for reading that are on the server that the applet was downloaded from? I have not tried it yet, but I believe this violates Java's sandbox (heaven forbid I start doing applet signing, certificates, etc...). I know I can write a server that the applet will connect to and download the data, but that seems like too much trouble (plus my Linux box just died so I don't have my own server anymore). Anybody know if it's possible?

Summary: I need to know if I can open and read files with an applet - the applet and file I need to open are both on the same server.

Thanks in advance for any help!

EZ-E

<edit>
Well... I tried to sleep, and I couldn't think of anything but this problem since it pretty much stops my research dead in it's tracks. Anyways, somehow this solution popped into my head and seems to serve the purpose. I'll post it here in case anybody else needs it... or there is something wrong with what I'm doing (somebody will correct me right? ):

As long as the applet source is from the same place (server) as the data file, you can (if the source is not the same as the server, it will generate a security exception) do this:

Code:
URL dataStream = new URL("http://someURLWhereYourAppletIs/dataFileName");
BufferedReader in = new BufferedReader(new InputStreamReader(dataStream.openStream()));

String str;
while((str = in.readLine()) != null) {
  //... do your processing in here
}

Is it a too simple solution to be true? I've tested it already and it seems to work. Guess this kinda circumvents the sandbox (through a degree of separation) since the page that you access via the URL class can be a php, asp, etc. script which, in turn, can access any page/read write any files (on the server) that it wants to. Haven't seen anything on the web about this, so I thought I'd post it! All this may be common knowledge to you Java programmers (I'm still learnin'!), but it's definitely valuable knowledge for me... sorry for bein a noob Thanks to whoever read this!
</edit>

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Applet File Access on Server


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT