-
applet works in viewer but not browser.
I have an applet that displays files that are resident in a certain network
directory. I compile and run the script in JPad it it displays the files
fine. When I copy the class file to my intranet directory and run the applet
in the web browser, it doesn't show the files in the directory. The script
is below. If I'm going about this all wrong, please let me know - I'm a
beginner.
Thanks in advance..
---------------------------------------------
import java.io.*;
import java.awt.*;
public class jobPosting extends java.applet.Applet
{
String direct = "\\\\hostname\\path\\";
int ht = 50;
public void init()
{
resize(300,300);
setBackground(Color.green);
}
public void paint(Graphics g)
{ g.drawString("Test Message", 100, 125);
getFileList();
String[] direct;
File f = new File(System.getProperty("user.dir"));
direct = f.list();
for(int i=0; i< direct.length; i++)
{
g.drawString(direct[i], 50, ht);
ht = ht + 20;
}
}//end paint
public void getFileList()
{
//**** This shows files inthe current directory. ****
File dir = new File(System.getProperty("user.dir"));
String user_dir = System.getProperty("user.dir");
//**** This shows files in the directory as set above. ****
System.setProperty ("user.dir", direct);
user_dir = System.getProperty ("user.dir");
//System.out.println(direct);
}//end getFileList
}//end applet
----------------------------------------------
-
Re: applet works in viewer but not browser.
Tim,
To start with:
Inside the browser you are running inside the sandbox so you don't have permission
to the user's machine.
Two choices - Sign your applet
- Run the directory code on the server using a servlet
Get the code out of the paint method. I know you are just starting out.
The best place to put the file code would be in a non-visual class. That
what you could use it in either technique described above. But if you want
to for learning, leave it in the applet class.
Also, It looks like you are using the MS JVM in the browser. Don't limit
yourself to that - actually don't use it if you are going to develop software
someone else is going to use.
Mark
"Tim" <timbal25@yahoo.com> wrote:
>
>I have an applet that displays files that are resident in a certain network
>directory. I compile and run the script in JPad it it displays the files
>fine. When I copy the class file to my intranet directory and run the applet
>in the web browser, it doesn't show the files in the directory. The script
>is below. If I'm going about this all wrong, please let me know - I'm a
>beginner.
>Thanks in advance..
>---------------------------------------------
>import java.io.*;
>import java.awt.*;
>
>public class jobPosting extends java.applet.Applet
>{
> String direct = "\\\\hostname\\path\\";
> int ht = 50;
>
> public void init()
> {
> resize(300,300);
> setBackground(Color.green);
> }
>
> public void paint(Graphics g)
> { g.drawString("Test Message", 100, 125);
>
> getFileList();
>
> String[] direct;
> File f = new File(System.getProperty("user.dir"));
> direct = f.list();
>
> for(int i=0; i< direct.length; i++)
> {
> g.drawString(direct[i], 50, ht);
> ht = ht + 20;
> }
> }//end paint
>
> public void getFileList()
> {
> //**** This shows files inthe current directory. ****
> File dir = new File(System.getProperty("user.dir"));
> String user_dir = System.getProperty("user.dir");
> //**** This shows files in the directory as set above. ****
> System.setProperty ("user.dir", direct);
> user_dir = System.getProperty ("user.dir");
> //System.out.println(direct);
>
> }//end getFileList
>
>}//end applet
>----------------------------------------------
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks