简体   繁体   English

Java Webapp找不到本地服务器目录

[英]Java Webapp Cannot Find Local Server Directory

I have a Spring MVC 3.1 webapp running on Tomcat 5.5 on a CentOS server. 我有一个在CentOS服务器上的Tomcat 5.5上运行的Spring MVC 3.1 Web应用程序。 I have a controller that checks for the existence of a file located on a network share, which is mounted on the server ( /netshare/data/ ). 我有一个控制器,用于检查是否存在网络共享文件,该文件已安装在服务器( /netshare/data/ )上。 My application cannot seem to see this directory, however when I run a standalone java app with the same code, it is able to locate the directory and its contained files without error. 我的应用程序似乎看不到该目录,但是当我使用相同的代码运行独立的Java应用程序时,它能够找到该目录及其包含的文件,而不会出现错误。 Is there some configuration that needs to be done in Tomcat so that directories outside the webapp can be referenced by Java? 是否需要在Tomcat中进行一些配置,以便Java可以引用webapp之外的目录?

Here is my controller class: 这是我的控制器类:

@Controller
@RequestMapping("/Test")
public class TestController {

@RequestMapping(method=RequestMethod.GET)
public String showTest(Model model){
    List<String> messages = new ArrayList<String>();
    File dirTest = new File("/netshare/data");

    if (dirTest.isDirectory()){

        messages.add("Base directory found successfully!");

        File dataFileDir = new File("/netshare/data/dataFiles/");
        Integer fileId = 8000;

        File dataFile = new File(dataFileDir, fileId.toString() + ".pdf");
        if (dataFile.exists()){
            messages.add("Data file found!");
        }
        else {
            messages.add("Data file NOT found!");
        }
    }
    else {
        messages.add("Base directory not found!");
    }

    model.addAttribute("messages", messages);
    return "test";
}

Turns out it was a permissions issue with the Isilon server being accessed by the web server, and not an issue with either my webapp or Tomcat's configuration. 事实证明,这是Web服务器正在访问Isilon服务器的权限问题,而不是Webapp或Tomcat的配置问题。 Thank you everyone for the help. 谢谢大家的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM