Ima Miri
Ima Miri

Reputation: 967

How to get app path in grails?

I want to get application path in my application, but I haven't found any way. If anyone knows how can I get application path in my app, It would be great.

Many thanks,

Upvotes: 4

Views: 7042

Answers (3)

Ammar Bozorgvar
Ammar Bozorgvar

Reputation: 1278

copy this in your controller

print webRequest.baseUrl

Upvotes: 0

Daniel Wondyifraw
Daniel Wondyifraw

Reputation: 7713

I think , most of the time was difficult to find the path inside gsp. but , you can use this :

var path = "${resource()}"+"/mycontroller/myaction" ;

gives you the path of the application.

Inside controller like when you need to upload file :

def webRootDir = servletContext.getRealPath("/")
def userDir = new File(webRootDir, "/payload/${session.user.login}")
userDir.mkdirs()
uploadedFile.transferTo( new File( userDir, uploadedFile.originalFilename))

Upvotes: 1

user1791574
user1791574

Reputation: 1749

If you want to get absolute path for application, you can get like this.

String applicationPath = request.getSession().getServletContext().getRealPath("")

It will provide absolute path for application.

Upvotes: 7

Related Questions