How to create a new folder in my web application (to upload a photo album) using Grails on Tomcat?

I want to create a photo album. But I want to organize albums on the server in order to create new folders:

/ MyApp / MYAPP / albums / MyApp / albums / 1 / MyApp / albums / 2 ...

How can I do this on tomcat with Grails? It creates an entire new folder in tomcat / bin not in tomcat / webapps / myapp /

+3
source share
2 answers

I don't deal with Grails, but since it runs on top of the Servlet API, you can also find this answer (steering in the right direction).

ServletContext. GenericServlet -inherited getServletContext(). ServletContext#getRealPath(), - ( , java.io.File ).

String absolutePath = getServletContext().getRealPath("albums/1");
File file = new File (absolutePath);
// ...

java.io.File, , Tomcat/bin, .

, : webapp, , webapp ! webapp, - . , ( ), , .

+2

- , Config.groovy,

environments {
    production {
rootPath="/home/user/reports"
    }
    development {
rootPath="c:\\reports"
    }
    test {
rootPath="c:\\reports"
    }

, .

import org.codehaus.groovy.grails.commons.ConfigurationHolder as Conf
tempFile=new File(Conf.config.rootPath+"dirName")
tempFile.mkdir()
+6

Source: https://habr.com/ru/post/1742314/


All Articles