简体   繁体   中英

Java applet can't access non-public file on same webserver

I'm creating a Java Applet for a customer, and I've run into a problem where I need to read/write to a file on their web server, but that file can not, under any circumstances, be publicly accessible.

The Java Applet and the file are both on the same server, and I can put the file and the .jar file in the same folder if need be, but I've tried several different configurations including having them in the same folder and accessing the file with

test = WorkbookFactory.create(new File("test.xlsx"))

I've tried writing out the full path to the file, and nothing seems to work.

The error I'm getting is:

Caused by: java.security.AccessControlException: access denied ("java.io.FilePermission" "test.xlsx" "read")

What would be the best way to read/write to a file on the same server, that can't be seen publicly?

You seem to have a fundamental misunderstanding of how Java applets work. They do not run on the server, they run on the client, in the web browser. If the client's web browser doesn't have access to the file, the applet can't have access either.

Applets can't read or write files on the server because the Java code runs on the client -- ie, in the web browser itself. The best way to implement what you're looking for would be to create a servlet (or other server-side code module) that writes to the file, and enforces some kind of security. The applet can then talk to that servlet, and access to the file is protected in whatever manner you like. For example, the page in which the applet is embedded might contain a generated unique key, and the applet would use that key to access the servlet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM