Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/436.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Playframework 在Play Framework 2.3中,如何从控制器操作服务静态资产?_Playframework_Playframework 2.3 - Fatal编程技术网

Playframework 在Play Framework 2.3中,如何从控制器操作服务静态资产?

Playframework 在Play Framework 2.3中,如何从控制器操作服务静态资产?,playframework,playframework-2.3,Playframework,Playframework 2.3,在我的应用程序中,我需要提供公用文件夹中的静态文件。出于某些原因,我必须从Java控制器的动作中执行 我想到的第一个解决方案是: public class Central extends Controller { public static Result index() { return Assets.at("/public", "central/index.html", false); } } 但是Assets.at方法返回类型是play.api.mvc

在我的应用程序中,我需要提供公用文件夹中的静态文件。出于某些原因,我必须从Java控制器的动作中执行

我想到的第一个解决方案是:

public class Central extends Controller {
     public static Result index() {
         return Assets.at("/public", "central/index.html", false);
     }
}
但是
Assets.at
方法返回类型是
play.api.mvc.Action

有没有办法将其转换为类型
play.mvc.Result


或者通过其他优雅的方式从Java控制器操作中提供静态文件?

更改方法返回类型。 像这样:

public class Central extends Controller {
     public static play.api.mvc.Action<play.api.mvc.AnyContent> index() {
         return Assets.at("/public", "central/index.html", false);
     }
}
公共类中央扩展控制器{
public static play.api.mvc.Action index(){
返回Assets.at(“/public”,“central/index.html”,false);
}
}

我为你找到了答案:为什么你想要结果而不是行动?结果不能在操作外部使用。我可以,我想我应该从index()操作返回结果。但是我不知道play.api.mvc.Action有什么用。