Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 44

Thread: Java security

  1. #21
    Zosden's Avatar
    Zosden is offline Senior Member
    Join Date
    Apr 2008
    Posts
    384
    Rep Power
    7

    Default

    I don't have any control over the server. Is there away to just grab the files with the URL.
    My IP address is 127.0.0.1

  2. #22
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    If you know the names.

    PS This could go a lot faster if you would explain ALL of what your app is trying to do instead of a little bit at a time. Or is the design changing with every posting?
    Last edited by Norm; 07-31-2008 at 01:42 PM.

  3. #23
    Zosden's Avatar
    Zosden is offline Senior Member
    Join Date
    Apr 2008
    Posts
    384
    Rep Power
    7

    Default

    No here's what it does. It shows a picture I don't know the names before hand then it fades out a word scrolls across the screen then another picture fades in then out then another word scrolls. The pictures are just in the folder with the source files. The words come from a text file. The applet is going up on a web page that is on some server hosted by I think Yahoo.
    My IP address is 127.0.0.1

  4. #24
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    I don't know the names before hand
    If you don't know the names, then you will NOT be able to read them.
    Can you generate a file on the server that lists the names of all the files you want to be able to read? This would have to be done before the applet tries to read the file that lists the names.
    Another possiblity is if the files can be named in a standard way the the applet knows and can generate names from.
    For example - have the filenames start with "MyImage" and append an incrementing index to the name as the files are added to the server. The applet could start reading at the first index and continue until there was as NOT FOUND return.

  5. #25
    Zosden's Avatar
    Zosden is offline Senior Member
    Join Date
    Apr 2008
    Posts
    384
    Rep Power
    7

    Default

    Yeah I could do something like that could you direct me in how to go about doing this without having an application on the server side running.
    My IP address is 127.0.0.1

  6. #26
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    how to go about doing this
    Doing what?
    Who puts the files on the server? Talk to them about what you need?

  7. #27
    Zosden's Avatar
    Zosden is offline Senior Member
    Join Date
    Apr 2008
    Posts
    384
    Rep Power
    7

    Default

    The Files are just ftp on to it I have the URL for the folder how do I get them in java.
    My IP address is 127.0.0.1

  8. #28
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    Who does the ftp? He could make up a file with all the names of the files he's uploaded and ftp that to the site.
    To pass info to an Applet, use the <PARAM tag.

  9. #29
    Zosden's Avatar
    Zosden is offline Senior Member
    Join Date
    Apr 2008
    Posts
    384
    Rep Power
    7

    Default

    But how do I get access to those files from the applet. I know I can figure out the names of the files I just don't know how to retrieve them.
    My IP address is 127.0.0.1

  10. #30
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    I posted some code from an applet a while back in this thread that showed how to use a URL to read a file from a server. It involved using the applet's codebase to get the server address.

  11. #31
    Zosden's Avatar
    Zosden is offline Senior Member
    Join Date
    Apr 2008
    Posts
    384
    Rep Power
    7

    Default

    How does that work there's a lot of variables that aren't declared in that code. How do I read that into a buffered image
    My IP address is 127.0.0.1

  12. #32
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    I'd recommend reading the API doc for the classes used.
    Forget about the contents of my variables.

    Do a search for code examples of the classes used.

  13. #33
    Zosden's Avatar
    Zosden is offline Senior Member
    Join Date
    Apr 2008
    Posts
    384
    Rep Power
    7

    Default

    Do I read in the file till null and put that into a File then reread it with ImageIO?
    My IP address is 127.0.0.1

  14. #34
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    Read the API doc for ImageIO.read() - one form takes a URL as arg.

  15. #35
    Zosden's Avatar
    Zosden is offline Senior Member
    Join Date
    Apr 2008
    Posts
    384
    Rep Power
    7

    Default

    Java Code:
    import java.io.DataInputStream;
    import java.io.IOException;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.URLConnection;
    import java.util.Random;
    import java.util.Vector;
    
    
    public class WordGenerator 
    {	
    	private Vector<String> myWords;
    	
    	private Random rand;
    	
    	public WordGenerator()
    	{
    		rand = new Random();
    		
    		myWords = new Vector<String>();
            
            this.setupVector();
    	}
    
    	@SuppressWarnings("deprecation")
    	private void setupVector() 
    	{
    		try 
    		{
    			URL                url;
    			URLConnection      urlConn;
    			DataInputStream    dis;
    
    			url = new URL("http://home.comcast.net/~zosden/SmashingApples/src/Words.txt");
    
    			urlConn = url.openConnection();
    			urlConn.setDoInput(true);
    			urlConn.setUseCaches(false);
    
    			dis = new DataInputStream(urlConn.getInputStream());
    			String s;
    
    
    			while ((s = dis.readLine()) != null) 
    			{
    				myWords.add(s);
    			}
    			dis.close();
    		}
    		catch (MalformedURLException mue) {}
    		catch (IOException ioe) {}
    	} 
    	
    	public String getWord()
    	{
    		return myWords.elementAt(rand.nextInt(myWords.size()));
    	}
    }
    When I open the web page up on my site it gives me tells me this.

    java.security.AccessControlException: access denied (java.io.FilePermission Words.txt read)
    at java.security.AccessControlContext.checkPermission (Unknown Source)
    at java.security.AccessController.checkPermission(Unk nown Source)
    at java.lang.SecurityManager.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkRead(Unknown Source)
    at java.io.FileInputStream.<init>(Unknown Source)
    at java.io.FileReader.<init>(Unknown Source)
    at WordGenerator.<init>(WordGenerator.java:30)
    at Window.init(Window.java:59)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)


    Those files are no where in my source code that I can see. I'll keep trying but help would be appreciated.
    Last edited by Zosden; 08-01-2008 at 07:09 PM.
    My IP address is 127.0.0.1

  16. #36
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    As I said before, Applets can read ONLY from the site they are loaded from. To get the address of that site use the getCodeBase() method.
    Look at post #8

  17. #37
    Zosden's Avatar
    Zosden is offline Senior Member
    Join Date
    Apr 2008
    Posts
    384
    Rep Power
    7

    Default

    The applet lets me read using ImageIO.read(URL) I'll try the getCodeBase() method and see if that fixes the problem.
    My IP address is 127.0.0.1

  18. #38
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    I noticed that you are using version 1.6 to compile your applet code. This will restrict viewers to those with 1.6 plugins (I have 1.5) If you compile code to 1.4 there will be more possible viewers.

    How are you testing the applet? Do you have a server like Tomcat on your PC that you can use to allow quick tests? I would recommend having your own server. I suppose you do with your signature.

    For testing this I/O stuff, I'd recommend writing a 20 line applet that reads a file and displays it contents. Using your own server you can quickly make changes to the code and test it in a few minutes.

  19. #39
    Zosden's Avatar
    Zosden is offline Senior Member
    Join Date
    Apr 2008
    Posts
    384
    Rep Power
    7

    Default

    I got it to work. Thanks for the help. You can see it if you like at my web page.

    Click on my applet on the left

    Wikipedia that IP Address btw. How do you change which version you compile it in I just been using the command prompt.
    My IP address is 127.0.0.1

  20. #40
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    Look at the doc for the java command. I think it has an option to define what the output should be. I haven't tried it, I have 1.4, 1.5 and 1.6 compilers available.
    Start another thread for the compiler option if you need help. Be sure to say what you are trying to do.

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. Replies: 3
    Last Post: 01-14-2010, 07:45 PM
  2. Replies: 0
    Last Post: 03-31-2008, 04:35 PM
  3. Replies: 4
    Last Post: 08-10-2007, 10:09 PM
  4. java.security.AccessControlException
    By cecily in forum Java Applets
    Replies: 1
    Last Post: 08-06-2007, 02:49 AM
  5. Replies: 1
    Last Post: 07-23-2007, 11:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •