Solved

Loading image from file.

Posted on 1998-03-17
7
184 Views
Last Modified: 2010-04-16
I've been loading image into memory using getImage(URL, String) which must be run from an applet. I now want to perform this code elsewhere, meaning I can use URL bit, besides I want to access my local directory. What methods exist to perform this operation.

Thanks

Jonc
0
Comment
Question by:Jonc
  • 3
  • 2
  • 2
7 Comments
 
LVL 16

Expert Comment

by:imladris
ID: 1233623
An applet can only access the server from which it was loaded.
If it was loaded from across the wire, you can only access that URL. If it loaded from the local machine, it can access a file on the local machine, but it can then not access a URL pointing to another machine.
0
 

Author Comment

by:Jonc
ID: 1233624
I thought it I signed the file with a digital signature, I could access the local files. Anyway, assuming I can't access another machine, how do I load a file from the local machine from a method that does not extend Applet as getImage is from Applet.

i.e. I have a class, extends applet, then I have a class that extends frame and wants to display the image. I really want the user to select using the FileDialog, which is what I had until I moved the code from the class extending Applet.
0
 
LVL 6

Expert Comment

by:gadio
ID: 1233625
 You can get permission to do that through digital signature in netscape and in the explorer. In the explorer you can also give an applet permissions to do almost anything . to do that  perform the following:  use view -> internet options -> security tab -> trusted site zone -> add sites -> (write the servers address) -> Add -> OK -> set Custom security level -> Settings... -> scroll to Java permissions ->   Check the "Custom" Checkbox -> Click the "Java Custom Settings..." -> Select the "Edit Permission" tab. -> Under "Run Unsigned Content" Check the "Enable" Checkbox -> Click "OK" -> Click "OK" -> Click Apply -> Click "OK".
 
   Once you have a trusted applet, all you have to do is use a URL the same way you did before but direct it to the local disk (like   new String urlname("file:///images/king.jpg");  ). Use this new URL instead of the old one and load the image the same way.

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Jonc
ID: 1233626
Excellent, just what I wanted, how do I change this to grade your response qadio?

Do I reopen and you type in something irrelevant and I grade you on that?
0
 
LVL 6

Expert Comment

by:gadio
ID: 1233627
Reject the previously given answer, and then I'll write an answer here.

0
 
LVL 16

Expert Comment

by:imladris
ID: 1233628
Thank you, learned something here.

It is perhaps worth noting consequences though. If you aren't the only user of the code, then anyone else who wants to use it will have to have the relevant stuff on their drive and, more importantly, bypass their security as indicated above. This, of course, opens them up to malicious applets.

0
 
LVL 6

Accepted Solution

by:
gadio earned 50 total points
ID: 1233629
 imladris: yes, the person using that method should have all the relevant stuff on his machine, or this stuff should be downloaded to his machine by this applet. Anyway, this is not an applet working model anymore, its more of an application working model. The security is a problem, but opening the site as I indicated in my answer (I'll quote it again) allows only to the applets coming from that site to access restricted resources, so the problem is limited if you consider that site "safe".


The answer again:
-----------------
  You can get permission to do that through digital signature in netscape and in the explorer. In the explorer you can also give an applet permissions to do almost anything . to do that  perform the following:  use view -> internet options -> security tab -> trusted site zone -> add sites -> (write the servers address) -> Add -> OK -> set Custom security level -> Settings... -> scroll to Java permissions ->   Check the "Custom" Checkbox -> Click the "Java Custom Settings..." -> Select the "Edit Permission" tab. -> Under "Run Unsigned Content" Check the "Enable" Checkbox -> Click "OK" -> Click "OK" -> Click Apply -> Click "OK".
     
   Once you have a trusted applet, all you have to do is use a URL the same way you did before but direct it to the local disk (like    new String urlname("file:///images/king.jpg");  ). Use this new URL instead of the old one and load the image the same way.

0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This video teaches viewers about errors in exception handling.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now