Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to read file into applet in weblogic server

 
feroz pasha
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1226
13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1226
13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Norm Radder
Bartender
Posts: 1226
13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1226
13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic