Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 258
  • Last Modified:

How to read a file fram an Applet in NS and IE

Could anyone be so kind to explain, how I read a textfile in to an applet, in both NetScape Communicator, and Internet Explorer >4.0. I need a common way, so I can use the same applet. Please explain every security aspect involved.
Your solution should be able to read the file on either a local file system, or the net.

Need more information, just ask !!!

Sources is welcome :-)
0
KE
Asked:
KE
1 Solution
 
evijayCommented:
I want to know what you mean by a local file system. Is it the filesystem of the client on which the browser is running or is it the filesystem of the host from which the applet is loaded.

Just remember one thing, An applet is not allowed to open, read/write files, open a socket connection to any host other than the host from which it is loaded.

if it is the filesystem of the host from which the applet is loaded, you need to write a proxy server (a java application which listens at a particular socket port and receives and processes requests - use ServerSocket) at the host which need to be running when the applet gets executed. The applet uses a socket connection to connect to that proxy server and forwards the request of reading the file to the proxy server  which reads the file and sends it back to the applet thru the socket connection.

Now if you want an applet to read the file from web, again the applet passes the url to the proxy server application which inturn uses the URL class to access that url, read its content and pass it onto the applet thru the socket connection.

See the java telnet applet in developer.javasoft.com site which employes a proxy server to emulate the telnet application.



So, if you want to read file from the file system from which the applet has originated or from the net, no special security considerations are required. Just use a proxy server. If you feel that this approach is too cumbersome, you need to sign the applet. Again here comes the problems with the incompatabilities of browsers and there is no  way to sign the applet that supports both ie and netscape browsers (because of browser wars).

If you want to read the data from the local file system of the client browser system, you need to sign the applet (the procedure varies for different browsers).

For more info go to
http://www.developer.com/reference/library/1575212986/htm/toc.htm 
and see the java security chapter.

For more info on signing the applets for netscape and ie go thru these to articles which explain in step by step manner how to do that in both these browsers

http://www.javareport.com/features/9801/sommers.html
http://www.javareport.com/features/9802/sommers.html

Dont think that i am giving the pointers. The author of the articles is an expert and he can explain the things in a more clear way than me.



0
 
KEAuthor Commented:
Thanks, for your huge answer.

I know it's a little late, however I was about to change the text of the question with some additional information.

I need to read (and only read) 5 ASCII based data files and some images, into a memory structure in the applet. In the meantime between your answer, I was looking at various methods to do this.
I found that I might be able to put the files into the distributed JAR file. The documentation states, that there should be no security restrictions to a JAR file - and if so, I would be very happy.
What I'm trying to figure now, is how to read a file from an JAR archive.
Currently I'm using this method to read a file:
BufferedReader in = new BufferedReader(new InputStreamReader(theURL.openStream()));
(which fails in Netscape)
How do I get this to work with JAR archives ?

0
 
evijayCommented:
KE,

Whether it is a jar file or any other file, the basic rule is
"An applet cannot read or write files since the browser security manager doesnt allow it to do that".

You can go thru the applet security restrictions page if you want.
A jar file is a file like any other file and u will read it using jar api (very simple api). But still, note that since you want to read a file, you will have to open a file which the applet security manager doesnt allow !!.

I have the source code
for applet security manager (for applet viewer) and i saw that clearly the security manager is not allowing to do that.

There is no way that you can read the files from jar archive. If you found the answer, i would be glad to use that one. I went thru many books and finally i have to resort to understanding the source code for appletviewer security manager and i found that it is not allowed unless it is signed.

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
KEAuthor Commented:
OK, I understand.

But if you can load an image from a JAR into your toolbars etc. (without any security restrictions) then I suppose you can load an ASCII file as well - Well, I don't know if you actually can do it, but it sounds resonable.

However I'm seeking the easiest way of getting external data into my applet. I don't actually mind if it's compiled into the code, but I don't know how to do this either.

So what do you think is the easiest way of reading (or compiling) images and ASCII files into the memory of the Applet ?

0
 
KEAuthor Commented:
I've found that I can use getResourceAsStream(), and I guess the next part would be, to get the JAR signed for use in NetScape (IE runs perfect).

0
 
jpk041897Commented:
Actualy, you can read any file you want as a stream if you read it from the server from both MSIE and Netscape. The problems start once it has been written on the local file system.

Additionaly, there is a free class lib available that can read data and immage files from a JAR or zip file, you interested?
0
 
webster030697Commented:
If you have access to the web server that is serving the applet, you could write a servlet to serve the files you need, and then the applet can get them through a socket connection to the servlet.
0
 
KEAuthor Commented:
jpk:
I'm looking for a solution, which will work on a local filesystem (i.e. CD-ROM). IE works perfectly, but NetScape throws a lot of exceptions, about verification etc.

webster:
OK, but as mentioned to jpk, I'm looking for a solution that will work on a local filesystem. As I understand, servlets is not supported unless you have a server ?

Thanks...
0
 
evijayCommented:


To read file from local file system
go to this example


http://java.sun.com/security/signExample/index.html

This uses javakey. Now, for netscape you have to use zigbert and for ie you have to use cabsign tools

The procedure is available in

              http://www.javareport.com/features/9801/sommers.html 
              http://www.javareport.com/features/9802/sommers.html 
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now