问题
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