wood burning stoves 2.0*
The moose likes Applets and the fly likes how to read file into applet in weblogic server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "how to read file into applet in weblogic server " Watch "how to read file into applet in weblogic server " New topic
Author

how to read file into applet in weblogic server

feroz pasha
Greenhorn

Joined: Aug 22, 2008
Posts: 13
i am using applet code in jsp page in weblogic server so pl help me in my jsp page it is showing all components

now i want to read file and display in appplet without server it is working but with server how to work i am not getting any permission should be kept
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 685
Here's some code I've used to read a file from a server:

[ August 28, 2008: Message edited by: Norm Radder ]
feroz pasha
Greenhorn

Joined: Aug 22, 2008
Posts: 13
sir
in my web based project i need to read file from directory and display it in applet which in turn displayed in html means applet code is embedded in html .

and this is running through web server tomcat tell now applet is displaying all components in html next step is to read the file and display it

when i directly display without server by double clicking html it will show file read in applet and displayed in html

then how shell i do it through server can any body guide me its urgent i am not getting

when i try to do this it is showing exception
c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
l: dump classloader list
m: print memory usage
o: trigger logging
p: reload proxy configuration
q: hide console
r: reload policy configuration
s: dump system and deployment properties
t: dump thread list
v: dump thread stack
x: clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------

The Direcory location=null
Full directory path=/localhost:7001/appletcodenull
java.security.AccessControlException: access denied (java.io.FilePermission \localhost:7001\appletcodenull read)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkRead(Unknown Source)
at java.io.File.isDirectory(Unknown Source)
at Backup.init(Backup.java:131)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

and my code to read file in applet is this
///============Reading from file==========

questionDir=getParameter("questionDir");
dirName=getCodeBase()+"";
System.out.println(dirName);
dirName=(dirName.substring(0,dirName.length()));
System.out.println(dirName);
dirName=dirName.substring(6,dirName.lastIndexOf('/'));
System.out.println(dirName);
dirName=dirName+questionDir;
System.out.println(dirName);
File f=new File(dirName);
if(f.isDirectory())
{
noOfFiles=f.list();
}

readFile();// it is method calling from init()method
==============================================
public void readFile()
{

String line;
InputStream in;

try
{
fileToRead=dirName+File.separator+"Question"+(countFile+1)+".java";
in = new FileInputStream(fileToRead);
BufferedReader bf = new BufferedReader(new InputStreamReader(in));
strBuff = new StringBuffer();
while((line = bf.readLine()) != null)
{
strBuff.append(line + "\n");
}
questionArea.append(strBuff.toString());
}
catch(IOException e)
{
e.printStackTrace();
}
countFile++;
}
-------------------------------------------------------------------

if any changes are there correct it pl
its urgent
thanks
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 685
i need to read file from directory

An applet without permission can NOT look/read at the local file system. It can get(read) files from the server without permission.

java.security.AccessControlException: access denied (java.io.FilePermission \localhost:7001\appletcodenull read)
...
at java.io.File.isDirectory(Unknown Source)
at Backup.init(Backup.java:131)

The above shows that at line 131 in Backup you are trying to look at the local file system. NOT ALLOWED!

I posted some code that can be used to read/get a file from the server.
Did you see that?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15957
    
  19

Originally posted by Norm Radder:

An applet without permission can NOT look/read at the local file system. It can get(read) files from the server without permission.


No it can't. A web server is not a file server.

The only ways an applet can read "files" from the server are these:

1. The web server is willing to package the content of the desired file in an HTTP response and serve it back in response to an HTTP request.

2. The applet is signed and the server file is visible through a file server. This file server may be on the same machine as the web server, but a file server is a completely different application from the web server, using different protocols, different network ports and different client and server software.
[ September 01, 2008: Message edited by: Tim Holloway ]

Customer surveys are for companies who didn't pay proper attention to begin with.
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 685
A web server is not a file server.

Interesting differentation:
From Google:
HTTP: every web server program operates by accepting HTTP requests from the client, and providing an HTTP response to the client.

a file server is a completely different application from the web server


Could you explain?
I'm not familiar with weblogic, perhaps their server works differently from common ones on the internet. Then your quotes above could say that (ie use weblogic server vs just web server).

When I said an applet could read/get files from its server, I didn't mean any file on the server. Of course there are restrictions.
[ September 01, 2008: Message edited by: Norm Radder ]
feroz pasha
Greenhorn

Joined: Aug 22, 2008
Posts: 13
ya i got your code and woked it
now my code is working through web logic server

thank you very much

weblogic is a server that is aplication server(that handle servlet jsp, ejb)


---------------------------------

i have another doubt

now my applet code is embedded in servlet code
if i write System.out.println("any msg"); in servlet it will be showing server console

but if i write System.out.println("any msg"); in applet and try to run in server it will not be showing in server console
tell me the reason

pl pl pl
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 685
if i write System.out.println("any msg"); in applet and try to run in server it will not be showing in server console

How/why are you running an Applet in the server?
Applets normally run in a client's browser.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to read file into applet in weblogic server
 
Similar Threads
applet not loaded
How to configure Applets with weblogic server
JSP & Servlet
Download a File From Server
Including a jar file in an Applet