bonjour a tous,
je tiens a préciser que je suis débutante et la doc ne m'a pas beaucoup aider . Alors voila je veux creer des utilisateur sur mon application mais sans base de données, un utilisateur aurais un nom, prenom, login, password ensuite j'enregistre les informations dans un fichier preperties par exemple pour les utiliser lors de la connexion ou la modification
voici mon formulaire dans index.ftl.html
et voici mon controleur ApplicationController
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 <#import "../layout/defaultLayout.ftl.html" as layout> <@layout.myLayout "Home page"> <h1>${i18n("hello.world")}</h1> <p>${i18n("hello.world.json")}</p> <form action="/utilisateur" method="post"> <table class="form"> <tr> <th><label for="nom"> Nom </label></th> <td><input class="input_full" type="text" id="nom" name="nom" /> </td> </tr> <tr> <th><label for="prenom"> Prenom </label></th> <td><input class="input_full" type="prenom" id="prenom" name="prenom" /></td> </tr> <tr> <th><label for="login"> Login </label></th> <td><input class="input_full" type="text" id="login" name="login" /></td> </tr> <tr> <th><label for="password"> Password </label></th> <td><input class="input_full" type="password" id="password" name="password" /></td> </tr> </table> <p> <input type="submit" value="Send" /> <input type="reset" value="Reset"> </p> </form> <a href="/hello_world.json">Hello World Json</a> </@layout.myLayout>
et voici mon bean : utilisateur
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56 /** * Copyright (C) 2013 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package controllers; import ninja.Context; import ninja.Result; import ninja.Results; import ninja.params.PathParam; import com.google.inject.Singleton; @Singleton public class ApplicationController { public Result index() { return Results.html(); } public Result helloWorldJson() { SimplePojo simplePojo = new SimplePojo(); simplePojo.content = "Hello World! Hello Json!"; return Results.json().render(simplePojo); } public static class SimplePojo { public String content; } public Result utilisateur(Context context, utilisateur utilisateur){ return Results.html().render(utilisateur); } }
et voici ma classe routes
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package controllers; public class utilisateur { private String nom; private String prenom; private String login; private String password; public String getNom() { return nom; } public void setNom(String nom) { this.nom = nom; } public String getPrenom() { return prenom; } public void setPrenom(String prenom) { this.prenom = prenom; } public String getLogin() { return login; } public void setLogin(String login) { this.login = login; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } }
je suis vraiment bloqué et je sais pas comment continuer pour arrivé a faire ce que je veux c-à-d enregistrer mes utilisateurs et établir une connexion
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 /** * Copyright (C) 2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package conf; import ninja.AssetsController; import ninja.Router; import ninja.application.ApplicationRoutes; import controllers.ApplicationController; public class Routes implements ApplicationRoutes { @Override public void init(Router router) { router.GET().route("/").with(ApplicationController.class, "index"); router.GET().route("/hello_world.json").with(ApplicationController.class, "helloWorldJson"); router.GET().route("/utilisateur").with(ApplicationController.class, "utilisateur"); /////////////////////////////////////////////////////////////////////// // Assets (pictures / javascript) /////////////////////////////////////////////////////////////////////// router.GET().route("/assets/webjars/{fileName: .*}").with(AssetsController.class, "serveWebJars"); router.GET().route("/assets/{fileName: .*}").with(AssetsController.class, "serveStatic"); /////////////////////////////////////////////////////////////////////// // Index / Catchall shows index page /////////////////////////////////////////////////////////////////////// router.GET().route("/.*").with(ApplicationController.class, "index"); }
Partager