Welcome to Play
Congratulations, you’ve just created a new Play application. This page will help you with the next few steps.
You’re using Play @play.core.PlayVersion.current
Why do you see this page?
The conf/routes
file defines a route that tells Play to invoke the HomeController.index
action whenever a browser requests the /
URI using the GET method:
# Home page
GET / controllers.HomeController.index
Play has invoked the controllers.HomeController.index
method to obtain the Action
to execute:
def index = Action {
Ok(views.html.index("Your new application is ready!"))
}
An action is a function that handles the incoming HTTP request, and returns the HTTP result to send back to the web client.
Here we send a 200 OK
response, using a template to fill its content.
The template is defined in the app/views/index.scala.html
file and compiled as a Scala function.
@@(message: String)
@@main("Welcome to Play") {
@@play20.welcome(message)
}
The first line of the template defines the function signature. Here it just takes a single String
parameter.
This template then calls another function defined in app/views/main.scala.html
, which displays the HTML layout, and another
function that displays this welcome message. You can freely add any HTML fragment mixed with Scala code in this file.
Is this your first time?
If you're not already using it, checkout out Activator. If you start the Activator UI, by running:
$ activator ui
You can get access to great templates and tutorials that demonstrate how to write Play applications.
Need to set up an IDE?
You can start hacking your application right now using any text editor. Any changes will be automatically reloaded at each page refresh, including modifications made to Scala source files.
If you want to set-up your application in Eclipse or any other Scala IDE, check the Setting up your preferred IDE page.
Need to connect to a database?
You can quickly set-up a development database (either in-memory or written to the file system),
by adding these lines to the conf/application.conf
file:
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:play"
If you need to connect to another JDBC-compliant database, first add the corresponding driver library
to your application dependencies in build.sbt
e.g.:
libraryDependencies += "mysql" % "mysql-connector-java" % "5.1.38"
Then add the corresponding JDBC configuration to the conf/application.conf
file:
db.url=jdbc:mysql:database_name
db.driver=org.mysql.Driver
db.user=root
db.pass=secret
Need more help?
When your application is run from the Play console, you can access the current documentation directly, at the /@@documentation URL or go to http://www.playframework.com.
The Play Google Group is where Play users come to seek help, announce projects, and discuss issues and new features. If you don’t have a Google account, you can still join the mailing list by sending an e-mail to play-framework+subscribe@@googlegroups.com.