开发者

Relative URL to server path conversion - Grails

In a custom tag, I am r开发者_如何学Pythoneceiving as a parameter the url of a file, which I need to open.

I have this

/content/data.html

which is the output from

${createLinkTo(dir:'content',file:'data.html')}:

and I need the 'server path':

C:\mygrailsapp\web-app\content\data.html


You can use the Spring application context to find resources. This works if it's under web-app folder:

class FooController {

   def grailsApplication

   def myAction = {
      String path = params.path // '/content/data.html'
      def resource = grailsApplication.mainContext.getResource(path)
      String text = resource.inputStream.text
      ...
   }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜