一尘不染

FileNotFoundException(权限被拒绝)

tomcat

全部,我使用commons-FileUpload允许我的学生通过课程网站将他们的作业上传到我的服务器。在我的本地计算机上运行tomcat /
eclipse可以正常工作。但是,在我的服务器上进行测试时,我通过digitalocean.com获得了FileNotFoundException(PermissionDenied)。

堆栈跟踪:

java.io.FileNotFoundException:
 /uploads/cosc111fall2013/Assignment1/Program1.java (Permission denied)
    at java.io.FileOutputStream.open(Native Method)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:209)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:160)
    at org.apache.commons.fileupload.disk.DiskFileItem.write(DiskFileItem.java:394)
    at uploadServlet.Uploader.doPost(Uploader.java:127)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)

令人反感的代码:

try {
            for (FileItem fi : uploaded) {
                fi.write(new File(saveDirectory + fileName + "_"
                        + FilenameUtils.getName(fi.getName())));
            }
        } catch (Exception e) {
            e.printStackTrace();
            response.sendRedirect("/uploadFailed.jsp");
            return;
        }

我只是修改了程序要写入的目录,所以它们都是drw-rw-rw-。有小费吗?


阅读 257

收藏
2020-06-16

共1个答案

一尘不染

答案是chmod 777而不是666。

2020-06-16