开发者

How to get Real path of the app in the play

开发者 https://www.devze.com 2023-02-05 09:12 出处:网络
like this in servlet use: public void doPost(HttpServletRequest request, HttpServletResponse response)

like this in servlet use:

public void doPost(HttpServletRequest request, HttpServletResponse response)  
  throws ServletException, IOException {  
    Strin开发者_运维技巧g  filePath = config.getServletContext().getRealPath("/");  
}

How to getRealPath in the play ?


Play is all about being easy, right ? so let's keep it simple:

I use Play.applicationPath which returns a File.

Note that there are a few other cool path in the Play class:

  • frameworkPath
  • javaPath
  • templatePath


VirtualFile path = play.vfs.VirtualFile.fromRelativePath("/");

This will give you the path. From the returned object, you can get the File object, get the path as a String using getName() and do normal file type checks, like exists() andisDirectory() etc.

Take a look at the javadoc for more info.

http://www.playframework.org/documentation/api/1.1/play/vfs/VirtualFile.html


You can use also : Play.getFile(".") this method return a object File

See javadoc : http://www.playframework.org/documentation/api/1.1/play/Play.html#getFile(java.lang.String)


In Play 2.0 (scala) try this:

import play.api.Play.current
val playPath = current.path.getAbsolutePath


In Java Play 2.x project, do this: play.Play.application().getFile(".").

0

精彩评论

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