View Full Version : Help open a local html file from clients system onto browser using applets

01-08-2008, 01:14 PM
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.

01-10-2008, 12:30 AM
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?