Bonjour,
Je développe une application J2EE intégrant SpringMVC.
J'utilise les annotations pour les controlleurs.
Voici un exemple de controlleur :
Ici donc je renvoie la vue hello.. Il s'agit d'une jsp.
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@Controller @RequestMapping("/test.html") public class Test { @Autowired private PortalService portalService; @RequestMapping(method = RequestMethod.POST) public String sayHello( @RequestParam(value="name",required=true) String name, @RequestParam(value="prenom",required=true) String prenom, ModelMap model, HttpServletResponse response) throws IOException { model.addAttribute("name",name); model.addAttribute("prenom",prenom); List<FirstDM> firstDMs = portalService.getAll(); model.addAttribute("firstDMs", firstDMs); System.out.println(firstDMs); return "hello"; } }
La question que j'ai est : est il possible d'accéder aux éléments de la ModelMap dans la jsp hello en utilisant du java deds.. Je m'explique :
Pour le moment ma jsp est de ce style :
qui permet d'afficher une table avec les éléments de firstDM.
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 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ page isELIgnored ="false" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Test !!</title> </head> <body> <p>Hello spring mvc vous donne votre nom qui est : ${name} et votre prenom est : ${prenom}</p> <table border="1" width="100%"> <thead> <tr> <th>Id</th> <th>Name</th> </tr> </thead> <c:forEach items="${firstDMs}" var="mobj" varStatus="status"> <tr> <td> ${mobj.id}</td> <td> ${mobj.name}</td> </tr> </c:forEach> </table> </body> </html>
Moi je voudrais un truc du genre :
et donc accéder aux éléments de la map dans une balise JAVA simple et pas en passant par le taglib jstl.. Est-ce possible? Si oui, comment?
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 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ page isELIgnored ="false" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Spring mvc hello !!</title> </head> <body> <p>Hello spring mvc vous donne votre nom qui est : ${name} et votre prenom est : ${prenom}</p> <table border="1" width="100%"> <thead> <tr> <th>Id</th> <th>Name</th> </tr> </thead> <% List<FirstDM> firstDMs = ???? for(FirstDM dm ! firstDMs) { // Des opérations en JAVA } %> </table> </body> </html>
Merci d'avance...
Partager