Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Loading image from file.

Posted on 1998-03-17
7
206 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

792 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