Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/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
scala播放如何将变量传递到页面_Scala_Playframework - Fatal编程技术网

scala播放如何将变量传递到页面

scala播放如何将变量传递到页面,scala,playframework,Scala,Playframework,在Scala+Play中,如何将变量放入响应中 第页 @lastName@firstName 在应用程序控制器中: def index = Action { implicit request =>{ request.setAttribute("lastName", "john"); // not work Ok(views.html.index("xxx")) } def index = Action { implicit

在Scala+Play中,如何将变量放入响应中

第页

@lastName@firstName

在应用程序控制器中:

   def index = Action {
    implicit request =>{
        request.setAttribute("lastName", "john"); // not work
        Ok(views.html.index("xxx"))
    } 
def index = Action {
    implicit request => {
        Ok(views.html.index(myStringVar = "Ooo!"))
    }
}
}

如果在java servlet中,我们可以这样做:

request.setAttribute("name", "value");
request.getRequestDispatcher("page.jsp").forward(request, response);

如何在Scala+Play中执行相同操作?

您希望使用视图/页面变量

在你看来:

@(myStringVar: String)
<b>Hello @myStringVar</b>

参考:

Rhys给出了正确的答案,但您应该花一些时间深入了解模板引擎的概念。模板是类型安全且已编译的,这为您提供编译时反馈(+编辑时反馈取决于您的IDE)。有关更多信息,请参阅。