Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.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
Routes `playdist`,`main.css`返回404_Routes_Assets_Playframework 2.0 - Fatal编程技术网

Routes `playdist`,`main.css`返回404

Routes `playdist`,`main.css`返回404,routes,assets,playframework-2.0,Routes,Assets,Playframework 2.0,创建新的示例play2应用程序: play new test 然后: 访问http://localhost:9000,我们可以看到正确显示的默认主页 但当我把它分开时: play dist 然后将生成的dist/test-1.0-SNAPSHOT.zip上传到服务器并解压缩,然后运行: cd test-1.0.SNAPSHOT ./start 然后访问http://myserver:9000,我发现找不到css文件 GET http://myserver:9000/assets/style

创建新的示例play2应用程序:

play new test
然后:

访问
http://localhost:9000
,我们可以看到正确显示的默认主页

但当我把它分开时:

play dist
然后将生成的
dist/test-1.0-SNAPSHOT.zip
上传到服务器并解压缩,然后运行:

cd test-1.0.SNAPSHOT
./start
然后访问
http://myserver:9000
,我发现找不到css文件

GET http://myserver:9000/assets/stylesheets/main.css
404
由于该应用程序是play2提供的内置示例,这不意味着它是play2的一个bug吗

附言:

路由
文件:

# Map static resources from the /public folder to the /public path
GET     /assets/*file                       controllers.Assets.at(path="/public", file)
play2提供的
Assets.scala
是:

object Assets extends Controller {

  def at(path: String, file: String): Action[AnyContent] = Action { request =>

    val resourceName = Option(path + "/" + file).map(name => 
        if (name.startsWith("/")) name else ("/" + name)).get

    if (new File(resourceName).isDirectory 
       || !new File(resourceName).getCanonicalPath.startsWith(new File(path).getCanonicalPath)) {
      NotFound
    } else {
    ...
  }

  ...
}

play似乎正在尝试查找磁盘上存在的目录和文件,但该
public
目录打包在
test-1.0-SANPSHOT/libs/test_2.9.1-1.0-SNAPSHOT.jar
,而不是真正的文件。

即使您执行“play-run”,也找不到该CSS文件,因此,将其打包到jar中与此无关。

为我解决了:只需检查main.css文件是否为空。

“play run”工作正常,并且找到了main.css的公共资产。我没试过“dist”,但“run”肯定有用??他们在邮件列表上说,Play会给你一个404,用于任何没有内容的文件,即使文件在那里,所以这就是问题所在。
object Assets extends Controller {

  def at(path: String, file: String): Action[AnyContent] = Action { request =>

    val resourceName = Option(path + "/" + file).map(name => 
        if (name.startsWith("/")) name else ("/" + name)).get

    if (new File(resourceName).isDirectory 
       || !new File(resourceName).getCanonicalPath.startsWith(new File(path).getCanonicalPath)) {
      NotFound
    } else {
    ...
  }

  ...
}