开发者

Java Servlet says file does not exist

I have developed a java servlet that monitors a folder on a network drive for new files then does some actions on them depending on what kind of file it is. It worked in Eclipse when Eclipse and Tomcat were running with each other, but now that I have deployed it onto a server(d开发者_StackOverflow中文版ifferent machine), the servlet keeps logging that it cannot find the folder to be mapped. The exact same network drive is mapped, and the folder definitely exists. This problem only occurs when the servlet is run on the server, not on the development machine.

Thanks!

PS: It is a Windows Server 2003 Enterprise Server with Tomcat v6 installed.


Are you using relative paths in your code to find the file? The paths to reach a file in your filesystem when the code runs in your IDE or local Tomcat is more than likely not the same path to reach the file as when it runs on other machines/environments.

Best bet is to remove the paths from your code completely and load them from a configuration file instead.


I finally figured it out.

It turns out that when Tomcat runs it (obviously) is running as a service. The service does not see things the same way as a user does. It turns out that Windows ONLY mounts network drives at the USER level. Therefore, according to the SYSTEM, the drive does NOT exist. The workaround was to use UNC pathnames.

I tried that originally, but it did not work, and the reason for that was because the service did not have correct permissions.

Thanks to everyone who helped me.

http://wiki.apache.org/tomcat/FAQ/Windows#Q7


Can you try output of this API to check if the file path is what you are expecting

http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletContext.html#getRealPath(java.lang.String)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜