gpt4 book ai didi

java - Tomcat 出现 AccessDeniedException?

转载 作者:行者123 更新时间:2023-12-01 18:26:35 24 4
gpt4 key购买 nike

我想访问我的网络应用程序之外的静态资源,这样它们就不会在每次重新部署时被破坏,但我似乎无法获取它们

我有一个 servlet,旨在通过 FileOutputStream 提供这些图像,但当我将其部署到 Tomcat 服务器上时,它无法获取文件 - 它给了我一个 java.nio.file.AccessDeniedException.

Catalina 日志文件中的错误

13-Feb-2020 16:53:10.621 SEVERE [http-nio-8080-exec-6] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [fileGetter] in context with path [] threw exception
java.nio.file.AccessDeniedException: C:\Users\micro\Pictures\WebsiteStuff\BlogPosts\Test Image 2020-02-12.jpg
at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108)
at java.base/sun.nio.fs.WindowsFileSystemProvider.newByteChannel(WindowsFileSystemProvider.java:235)
at java.base/java.nio.file.Files.newByteChannel(Files.java:374)
at java.base/java.nio.file.Files.newByteChannel(Files.java:425)
at java.base/java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:420)
at java.base/java.nio.file.Files.newInputStream(Files.java:159)
at java.base/java.nio.file.Files.copy(Files.java:3195)
at ImageGetterServlet.doGet(ImageGetterServlet.java:37)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:543)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:609)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:810)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1623)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:830)

考虑到我已允许访问 Catalina.policy 文件中的目录,这尤其奇怪。

Catalina.Policy

grant {
...
permission java.io.FilePermission "C:${file.separator}Users${file.separator}micro${file.separator}Pictures${file.separator}WebsiteStuff", "read, write";

};

无论出于何种原因,这段完全相同的代码(减去权限)在 Intellij 中完美运行。但是,这里无法访问该文件。

谁能告诉我为什么会发生这种情况?我是否设置了错误的权限/将权限放在了错误的位置?

编辑:这不是权限问题我授予了 Catalina.policy java.security.AllPermission 中的所有内容,但无济于事,我遇到了相同的异常。

最佳答案

我发现出了什么问题。 Tomcat 无法访问 Users 文件夹内的任何内容 - 可能是 Windows 10 特定问题。

我只是将我的目录放在 C: 驱动器中,这样路径现在是 C:/WebsiteStuff 并且一切正常。

关于java - Tomcat 出现 AccessDeniedException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60219410/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com