简体   繁体   中英

Java Webapp Cannot Find Local Server Directory

I have a Spring MVC 3.1 webapp running on Tomcat 5.5 on a CentOS server. 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/ ). 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. Is there some configuration that needs to be done in Tomcat so that directories outside the webapp can be referenced by Java?

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. Thank you everyone for the help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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