Hello and welcome to our community! Is this your first visit?
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
    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};

    for ( int i = 0 ; i < 3 ; i++ ) {
    Button b = new Button(link_buttons[i]);

    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);
    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:

    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 03:01 PM.

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Thanked 163 Times in 160 Posts
    Quote Originally Posted by imoracle View Post
    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