【发布时间】:2016-11-07 01:02:10
【问题描述】:
在 Scala + Play 中,如何将变量放入响应中?
在页面中
@lastName @firstName
在应用程序控制器中:
def index = Action {
implicit request =>{
request.setAttribute("lastName", "john"); // not work
Ok(views.html.index("xxx"))
}
}
如果在 java servlet 中,我们可以这样做:
request.setAttribute("name", "value");
request.getRequestDispatcher("page.jsp").forward(request, response);
如何在 Scala + Play 中做同样的事情?
【问题讨论】:
-
Rhys 有正确的答案,但您应该花一些时间来深入了解模板引擎的概念。模板是类型安全的和编译的,它为您提供编译时反馈(+ 编辑时反馈,具体取决于您的 IDE)。请参阅playframework.com/documentation/2.5.x/ScalaTemplates#Overview 了解更多信息。
标签: scala playframework