The High Velocity Web Framework For Java and Scala : www.playframework.org
C'est le Symfony (Php) de Java ! Ce framework n'est pas basé sur J2EE, il embarque directement sont serveur (Netty).
Play Framework is the High Velocity Web Framework for Java and Scala. Play is based on a lightweight, stateless, web-friendly architecture. Built on Akka, Play provides predictable and minimal resource comsumption (CPU, memory, threads) for highly-scalable applications.
Play! utilise les frameworks
what-cloud-platform-supports-playframework
Présentations:
Tutoriels:
Autres:
Encore:
Livres:
Typesafe Activator Templates: https://www.typesafe.com/activator/templates
Les dossiers pour le cache:
Après installation, création et run du projet essai01 (activator new essai01 play-java) le volume utilisé sur le disque est de 822,6 Mo:
Un run ressemble à:
$ activator run [info] Loading project definition from /home/cyrille/Taf/CEFIM_2016_Java/essai01/project [info] Set current project to essai01 (in build file:/home/cyrille/Taf/CEFIM_2016_Java/essai01/) --- (Running the application, auto-reloading is enabled) --- [info] p.c.s.NettyServer - Listening for HTTP on /0:0:0:0:0:0:0:0:9000 (Server started, use Ctrl+D to stop and go back to the console...)
Puis à la visite de http://localhost:9000/:
[info] Compiling 6 Scala sources and 2 Java sources to /home/cyrille/Taf/CEFIM_2016_Java/essai01/target/scala-2.11/classes... [info] 'compiler-interface' not yet compiled for Scala 2.11.6. Compiling... [info] Compilation completed in 6.524 s [info] - play.api.Play - Application started (Dev)
Par exemple dans SecureSocial2 il y a les sous-projets javaDemo et scalaDemo. Pour les runner:
$ activator 'project javaDemo' run
Run avec le serveur http écoutant le port 9001:
$ activator "~run 9001"
Pour changer le port du debuggage (JPDA Port)
$ activator -jvm-debug 9999 ~run
Chat:
Map update:
Accesing directly the request body:
package controllers; import play.mvc.*; import views.html.*; import java.util.Map; public class JavaPoster extends Controller { public static Result save() { final Map<String, String[]> values = request().body().asFormUrlEncoded(); final String name = values.get("java_name")[0]; final String surname = values.get("java_surname")[0]; return ok(index.render(String.format("You are %s, %s",surname, name))); } }
Or using a DynamicForm:
package controllers; import play.mvc.*; import views.html.*; import play.data.DynamicForm; public class JavaPoster extends Controller { public static Result save() { final DynamicForm form = form().bindFromRequest(); final String name = form.get("java_name"); final String surname = form.get("java_surname"); return ok(index.render(String.format("You are %s, %s",surname, name))); } }