Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help open a local html file from clients system onto browser using applets

    Well I have been hitting my head against the wall since two days. Read about 100 of forums but with no solution. Here is what I am trying:

    I logs onto my local website, http://localhost/IO.html. As soon as I opens up, i create a file jaborandi.html on my system, say with Hello World in it. Now I want to display the file on the browser. Here is my sample code:

    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;
    import java.net.*;

    public class IO extends Applet implements ActionListener{
    public void init(){
    String [] link_buttons = { "http://www.yahoo.com" , "http://www.google.co.in" , "file:///C|/Inetpub/wwwroot/music/jaborandi.html"};
    Color [] c = { Color.yellow , Color.red , Color.orange};
    getParent().setBackground(Color.white);

    for ( int i = 0 ; i < 3 ; i++ ) {
    Button b = new Button(link_buttons[i]);
    b.addActionListener(this);
    b.setBackground(c[i]);
    add(b);
    }
    }

    public void actionPerformed(ActionEvent ae){
    //get the button label
    Button source = (Button)ae.getSource();

    String link = source.getLabel();
    try {
    AppletContext a = getAppletContext();
    URL u = new URL(link);
    System.out.println(u);
    a.showDocument(u,"_blank");
    }
    catch (MalformedURLException e) {
    System.out.println("Invalid URL");
    //do nothin
    }
    }
    }
    On the run I am printing the url onto the java console. When I clicks the button with http://www.yahoo.com and http://www.google.co.in on them, the new page opens up successfully. However when I click the third button with file:///C|/Inetpub/wwwroot/music/jaborandi.html onto it, nothing happens. No exception, no error.

    I am printing the url's on java console and here is wat i get thr:
    http://www.yahoo.com
    http://www.google.co.in
    file:/C|/Inetpub/wwwroot/music/jaborandi.html


    Also one interesting thing, if I try to open the applet locally, I mean with following url on the browser:

    file:///C:/Inetpub/wwwroot/music/Test/IO/IO.html ,

    and then try to open the local html file from here, it opens up successfully. While it was failing if I accessed the applet from a server.

    I am already signing this applet using jarsigner utility.

    I am helpless. There is no help, I have tried out all the posts over internet and no one supply with a clear solution.

    I have tried with Windows Vista and WinXP both. With all the browsers: Netscape, IE, Firefox. No success. With all servers IIS, Apache2, Apache2.0.

    Kindly throw some light if you know the answer to my problem.

    May be code snippet will be of grt grt help.
    Last edited by imoracle; 01-08-2008 at 02:01 PM.

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Quote Originally Posted by imoracle View Post
    Code:
    String [] link_buttons = { "http://www.yahoo.com" , "http://www.google.co.in" , "file:///C|/Inetpub/wwwroot/music/jaborandi.html"};
    applets cannot access the local filesystem unless they are signed and the user accepts the resposibility

    btw, did u try using "http://localhost/music/jaborandi.html" instead?
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow


  •  

    Posting Permissions

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