To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
This is a starter application that shows how Play works. Please see the documentation at https://www.playframework.com/documentation/latest/Home for more details.
## Running
Run this using [sbt](http://www.scala-sbt.org/). If you downloaded this project from http://www.playframework.com/download then you'll find a prepackaged version of sbt in the project directory:
```
sbt run
```
And then go to http://localhost:9000 to see the running web application.
## Controllers
There are several demonstration files available in this template.
- HomeController.java:
Shows how to handle simple HTTP requests.
- AsyncController.java:
Shows how to do asynchronous programming when handling a request.
- CountController.java:
Shows how to inject a component into a controller and use the component when
handling requests.
## Components
- Module.java:
Shows how to use Guice to bind all the components needed by your application.
- Counter.java:
An example of a component that contains state, in this case a simple counter.
- ApplicationTimer.java:
An example of a component that starts when the application starts and stops
when the application stops.
## Filters
- ExampleFilter.java
A simple filter that adds a header to every response.
Congratulations, you’ve just created a new Play application. This page will help you with the next few steps.
</p>
<blockquote>
<p>
You’re using Play @version
</p>
</blockquote>
<h2>Why do you see this page?</h2>
<p>
The <code>conf/routes</code> file defines a route that tells Play to invoke the <code>HomeController.index</code> action
whenever a browser requests the <code>/</code> URI using the GET method:
</p>
<pre><code># Home page
GET / controllers.HomeController.index</code></pre>
<p>
Play has invoked the <code>controllers.HomeController.index</code> method:
</p>
<pre><code>public Result index() {
return ok(index.render("Your new application is ready."));
}</code></pre>
<p>
An action method handles the incoming HTTP request, and returns the HTTP result to send back to the web client.
Here we send a <code>200 OK</code> response, using a template to fill its content.
</p>
<p>
The template is defined in the <code>app/views/index.scala.html</code> file and compiled as a standard Java class.
</p>
<pre><code>@@(message: String)
@@main("Welcome to Play") {
@@play20.welcome(message, style = "Java")
}</code></pre>
<p>
The first line of the template defines the function signature. Here it just takes a single <code>String</code> parameter.
Then this template calls another function defined in <code>app/views/main.scala.html</code> 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.
</p>
<blockquote>
<p>
<strong>Note</strong> that Scala is fully compatible with Java, so if you don’t know Scala don’t panic, a Scala statement is very similar to a Java one.
</p>
</blockquote>
<p>You can read more about <ahref="https://www.playframework.com/documentation/@version/ScalaTemplates">Twirl</a>, the template language used by Play, and how Play handles <ahref="https://www.playframework.com/documentation/@version/JavaActions">actions</a>.</p>
<h2>Async Controller</h2>
Now that you've seen how Play renders a page, take a look at <code>AsyncController.java</code>, which shows how to do asynchronous programming when handling a request. The code is almost exactly the same as <code>HomeController.java</code>, but instead of returning <code>Result</code>, the action returns <code>CompletionStage<Result></code> to Play. When the execution completes, Play can use a thread to render the result without blocking the thread in the mean time.
<p>
<ahref="@routes.AsyncController.message">Click here for the AsyncController action!</a>
</p>
<p>
You can read more about <ahref="https://www.playframework.com/documentation/@version/JavaAsync">asynchronous actions</a> in the documentation.
</p>
<h2>Count Controller</h2>
<p>
Both the HomeController and AsyncController are very simple, and typically controllers present the results of the interaction of several services. As an example, see the <code>CountController</code>, which shows how to inject a component into a controller and use the component when handling requests. The count controller increments every time you click on it, so keep clicking to see the numbers go up.
</p>
<p>
<ahref="@routes.CountController.count">Click here for the CountController action!</a>
</p>
<p>
You can read more about <ahref="https://www.playframework.com/documentation/@version/JavaDependencyInjection">dependency injection</a> in the documentation.
</p>
<h2>Need more info on the console?</h2>
<p>
For more information on the various commands you can run on Play, i.e. running tests and packaging applications for production, see <ahref="https://playframework.com/documentation/@version/PlayConsole">Using the Play console</a>.
</p>
<h2>Need to set up an IDE?</h2>
<p>
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.
</p>
<p>
If you want to set-up your application in <strong>IntelliJ IDEA</strong> or any other Java IDE, check the
<ahref="https://www.playframework.com/documentation/@version/IDE">Setting up your preferred IDE</a> page.
</p>
<h2>Need more documentation?</h2>
<p>
Play documentation is available at <ahref="https://www.playframework.com/documentation/@version">https://www.playframework.com/documentation</a>.
</p>
<p>
Play comes with lots of example templates showcasing various bits of Play functionality at <ahref="https://www.playframework.com/download#examples">https://www.playframework.com/download#examples</a>.
</p>
<h2>Need more help?</h2>
<p>
Play questions are asked and answered on Stackoverflow using the "playframework" tag: <ahref="https://stackoverflow.com/questions/tagged/playframework">https://stackoverflow.com/questions/tagged/playframework</a>
</p>
<p>
The <ahref="https://discuss.playframework.com">Discuss Play Forum</a> is where Play users come to seek help,
announce projects, and discuss issues and new features.
</p>
<p>
Gitter is a real time chat channel, like IRC. The <ahref="https://gitter.im/playframework/playframework">playframework/playframework</a> channel is used by Play users to discuss the ins and outs of writing great Play applications.