How can I render a simple html page using play framework?

百般思念 提交于 2020-02-01 04:57:24

问题


Is it a way to render a pure html file with play framework version 2? I don't want to put it in public/ folder because later on there will be some dynamic information added to it.


回答1:


Here is my solution:

in routes: I do some configurations as following.

GET     /hello.html                 controllers.Assets.at(path="/public/html", file="hello.html")
GET     /public/javascripts/jquery-1.9.0.min.js     controllers.Assets.at(path="/public/javascripts", file="jquery-1.9.0.min.js")
GET     /public/stylesheets/bootstrap.css           controllers.Assets.at(path="/public/stylesheets", file="bootstrap.css")

and then the file structure is as below:

public->HTML->hello.html
public->javascripts->jquery-1.9.0.min.js
public->stylesheets->bootstrap.css

for hello.html , here is its content.

<!DOCTYPE html>    
<html lang="en">
<head>
    <meta charset="utf-8">
    <link rel='stylesheet' type='text/css' href='/public/stylesheets/bootstrap.css'>
</head>    
<body>
    <script src="/public/javascripts/jquery-1.9.0.min.js" type="text/javascript"></script>
</body>
</html>

After these three steps, you can use outside HTML directly. No need to follow Play template to do front-end development work. So now, Play only is responsible for back-end. Front-end developer only needs to operate this public file to do development.




回答2:


Of course, put your whole static html ie. in index.scala.html and use simplest possible way:

public static Result index(){
    return ok(index.render());
}

That are the basics, you should go trough Play's documentation and samples




回答3:


GET / controllers.Assets.at(path="/public/html", file="index.html")

This is working in my case with play 2.0.1. Hierarchy is public - html ---index.html



来源:https://stackoverflow.com/questions/11126678/how-can-i-render-a-simple-html-page-using-play-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!