java.security.AccessControlException:文件可通过浏览器访问,但不在同一台服务器中 [英] java.security.AccessControlException: File accessible thru browser but not within same server
问题描述
正如您从引用链接中看到的,我可以通过url查看图片。然而,当我试图使用类似的代码来读取文件名
public void listFilesForFolder(final File folder){
for(final File fileEntry:folder.listFiles()){
if(fileEntry.isDirectory()){
listFilesForFolder(fileEntry);
} else {
System.out.println(fileEntry.getName());
$ b最终文件夹=新文件(/ home / you / Desktop);
listFilesForFolder(folder);
我得到一个安全异常
<$ p $ (java.io.FilePermission/ myImagesread)
java.security.AccessControlException:
有人知道这个问题吗?如何通过浏览器调用显示图像,然而服务器内部的调用本身会引发异常?我发现这很奇怪。
如果您将文件配置为静态资源,通过为服务静态内容而优化的独立服务器池。结果是该文件不能从您的应用程序打开。 资源文件可供应用程序打开和阅读。
这是 here。
打开资源时需要使用相对路径。您已经在上面显示了一个绝对路径。
So to not repeat myself too much, please refer to serve static image along side java google-enpoint api.
As you can see from the referenced link, I am able to view the image through the url. However, when I am trying to read filenames using similar code to
public void listFilesForFolder(final File folder) {
for (final File fileEntry : folder.listFiles()) {
if (fileEntry.isDirectory()) {
listFilesForFolder(fileEntry);
} else {
System.out.println(fileEntry.getName());
}
}
}
final File folder = new File("/home/you/Desktop");
listFilesForFolder(folder);
I get a security exception
java.security.AccessControlException: access denied ("java.io.FilePermission" "/myImages" "read")
Does anyone know the fix? How come the call thru the browser show the image and yet a call from within the server itself throws an exception? I find that strange.
If you've configured a file as a "static" resource, it'll be served up by a separate pool of servers that are optimized for serving static content. A consequence is that the file isn't available to be opened from your app. "resource" files are available for the app to open and read.
That's documented here.
You'll need to use a relative path when opening a resource. You've shown an absolute path above.
这篇关于java.security.AccessControlException:文件可通过浏览器访问,但不在同一台服务器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!