Accesing file list thro' applet from a web server
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   RAM_KUMAR
Posted On:   Friday, February 21, 2003 05:45 AM

In my program an applet should read an xml file resing in a web server.. point no:1 i use the code below to access the same xml file in my local machine. but if i host the same in my website, the applet is not reading the xml file although the xml file is present in the server. String ss = (this.getCodeBase()).toString(); ss = ss.substring(6); //to remove the file:/ ff = new File(ss+this.getParameter("xmlFile")+".xml"); boolean xmlExists = ff.exists(); if (xmlExists) { } In my local machine the boolean xmlExists returns true but it is false when the applet in my we   More>>

In my program an applet should read an xml file resing in a web server..


point no:1


i use the code below to access the same xml file in my local machine. but if i host the same in my website, the applet is not reading the xml file although the xml file is present in the server.


String ss = (this.getCodeBase()).toString();


ss = ss.substring(6); //to remove the file:/


ff = new File(ss+this.getParameter("xmlFile")+".xml");


boolean xmlExists = ff.exists();


if (xmlExists)
{
}


In my local machine the boolean xmlExists returns true but it is false when the applet in my website is running..



point no:2


Is there any way to get file or directory listing thro' applet when a file is hosted in the website..((ie)the list of the files residing in the server)



Thanks in advance


Ramkumar

   <<Less

Re: Accesing file list thro' applet from a web server

Posted By:   Christopher_Koenigsberg  
Posted On:   Friday, February 21, 2003 11:38 AM

You could pull down the XML in the client Web browser DOM (and reference it there, from the applet), with a "src=" attribute e.g. on an XML "data island" in the Web page (but I am not sure if there is a W3C standard way to do this, embedding XML pulled from a remote datasource into an HTML page, aside from the Microsoft proprietary IE-only way?).

Re: Accesing file list thro' applet from a web server

Posted By:   Laxman_Subramanian  
Posted On:   Friday, February 21, 2003 10:18 AM

Either jar the file along with the applet classes like

InputStream is = getClass().getResourceAsStream("lp.xml");

BufferedReader br = new BufferedReader(new InputStreamReader(is));

java.io.BufferedInputStream bis = new java.io.BufferedInputStream(is);



or open a url connection and read the file as

URL getconnect = null;

URLConnection fetchfile = null;

try {
getconnect = new URL(this.getCodeBase().toString()+lp.xml);

fetchfile = getconnect.openConnection();

BufferedReader in = new BufferedReader(new
InputStreamReader(fetchfile.getInputStream()));
}

These are the two ways by which you can read the file from an applet residing on the same webserver . Applets when run they run on the clients box , so its can access a file on the webserver as a normal file for more info see sanbox restrictions.
About | Sitemap | Contact