GWT 文件上传 java.security.AccessControlException: 访问被拒绝 (java.io.FilePermission
我有一个文件上传 Servlet 并尝试将一些文件存储为:
try{
File uploadedFile = new File(UPLOAD_DIRECTORY + fileName);
File uploadedFile = new File("/"+fileName);
item.write(uploadedFile);
}
catch (Exception e) {
e.printStackTrace();
}
之后我收到以下错误:
java.security.AccessControlException: access denied (java.io.FilePermission /untitled.html write)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
at java.security.AccessController.checkPermission(AccessController.java:546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
如何修复它?
I have a file upload Servlet and try to store some files as:
try{
File uploadedFile = new File(UPLOAD_DIRECTORY + fileName);
File uploadedFile = new File("/"+fileName);
item.write(uploadedFile);
}
catch (Exception e) {
e.printStackTrace();
}
After that I get the following error:
java.security.AccessControlException: access denied (java.io.FilePermission /untitled.html write)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
at java.security.AccessController.checkPermission(AccessController.java:546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
How can I fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使应用服务器可写
/
(这对我来说似乎不是一个好主意)或将上传的文件存储在另一个可写位置。您似乎还尝试声明
uploadedFile
两次。从错误来看,UPLOAD_DIRECTORY
是/
或者您实际上正在使用第二行。也许您只需要在UPLOAD_DIRECTORY
中提供正确的位置?要回答有关 Java 策略文件的评论问题:
来自 安全性和权限java.sun.com 上的 :
有关设置文件系统权限的信息,请参阅文件权限部分策略文件。
重申我自己的评论,您还需要注意操作系统中的文件系统权限,其控制取决于您所使用的操作系统。
You could either make
/
writable by your app server (which doesn't seem like a great idea to me) or store your uploaded files in another writable location.You also appear to be trying to declare
uploadedFile
twice. From the error, it looks like eitherUPLOAD_DIRECTORY
is/
or you're actually using the second line. Perhaps you just need to supply the right location inUPLOAD_DIRECTORY
?To answer your comment-question about Java policy files:
From Security and Permissions on java.sun.com:
See the File Permission section for setting file system permissions in the policy file.
And to reiterate my own comment, you'll also want to pay attention to file system permissions in the OS, control of which will depend on the OS you're using.