[3054] in java-interest

home help back first fref pref prev next nref lref last post

No subject found in mail header

daemon@ATHENA.MIT.EDU (Mohamed Bazzi)
Fri Oct 27 20:08:55 1995

From: bazzi@rennes.enst-bretagne.fr (Mohamed Bazzi)
Date: Fri, 27 Oct 1995 23:26:04 +0100
Apparently-To: java-interest@java.Eng.Sun.COM

Hello,
My purpose is to write an applet to get a remote file. And to create an 
local entry. The URL of the file is given in a HTML page as parameter.

Here is the applet :

import java.applet.Applet;
import java.net.URL;
import java.io.InputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.*;



public class WBTest extends java.applet.Applet  {

	String StrUrl;
	URL Nurl;
	public void init() {
		StrUrl = getParameter("pt");
/* please see the HTML page below */
		resize(500,20);
		} 



public void start() {
	 	System.out.println(StrUrl);
		Nurl = new URL(StrUrl);
		System.out.println("Nurl");

		InputStream is = Nurl.openStream(); 
		System.out.println("is");

		int cpt = is.read(); 
		System.out.println("cpt");
/* at that stage "cpt" not displayed, so the read operation has failled */
		File f = new File("/usr/tmp","bocage.donnees");
		FileOutputStream fis = new FileOutputStream(f);

		while (cpt != -1) {
			System.out.println("cpt");
			fis.write(cpt);
			cpt = is.read();
		} 
		
	}

} 


Here is the HTML page :

<HTML>
<HEAD>
<TITLE>FILE MANIPULATION</TITLE>
</HEAD>

<BODY>
HERE IS THE OUTPUT OF MY PROGRAM:
<APPLET CODE="WBTest.class"	WIDTH=150  HEIGHT=25>
<param name= pt value="http://bloodmoney/cours_c">
</APPLET>
</BODY>
</HTML>

bloodmoney is the name of the server, and cours_c is the name of the file.

When i run the applet with appletviewer i had the following message :

Thread-5 find class WBTest
Opening stream to: file:/homes/bazzi/.www/WBTest.class to get WBTest
http://bloodmoney/cours_c
Nurl
*** Security Exception: socket.connect:->bloodmoney ***
sun.applet.AppletSecurityException security.socket.connect: ->bloodmoney
        at java.lang.Throwable.<init>(Throwable.java)
        at java.lang.Exception.<init>(Exception.java)
        at java.lang.RuntimeException.<init>(RuntimeException.java)
        at java.lang.SecurityException.<init>(SecurityException.java)
        at sun.applet.AppletSecurityException.<init>(AppletSecurityException.java:36)
        at sun.applet.AppletSecurity.checkConnect(AppletSecurity.java:299)
        at sun.applet.AppletSecurity.checkConnect(AppletSecurity.java:271)
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:100)
        at sun.net.www.http.HttpClient.get(HttpClient.java:225)
        at sun.net.www.http.HttpClient.handleUrl(HttpClient.java:423)
        at sun.net.www.http.HttpClient.<init>(HttpClient.java:452)
        at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:56)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:124)
        at java.net.URL.openStream(URL.java)
        at WBTest.start(WBTest.java:25)
        at sun.applet.AppletPanel.run(AppletPanel.java:268)
        at java.lang.Thread.run(Thread.java)


I have done the same with a stand-alone application and it works well, here the program :
import java.applet.Applet;
import java.net.URL;
import java.io.InputStream;
import java.io.File;
import java.io.FileOutputStream;

public class Test2WB  {

	String StrUrl = "http://bloodmoney/cours_c";
	URL  Nurl;

	public void ecrire() {
		
		Nurl = new URL(StrUrl);
		InputStream is = Nurl.openStream();
		System.out.println(StrUrl);
		int cpt = is.read(); 
		System.out.println("cpt");
		File f = new File("/usr/tmp","cours_c");
		FileOutputStream fis = new FileOutputStream(f);
		while (cpt != -1) {
			fis.write(cpt);
			cpt = is.read();
			System.out.println("cpt");
			} 
		}

	public static void main(String args[]) {

		Test2WB wb = new Test2WB();
		wb.ecrire();
	}

		
} 

Thanks to show me what's wrong with the applet.

-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post