Bonjour je suis sur un projet spring, je voudrais retourner sur la meme page d' une fois lorsque qu'on clique sur le bouton "ajouter" afin d'actualiser la liste des articles, mais lorsque je clique sur ajouter xa m'affiche exactement le meme text se trouvant dans return de ma methode @Responsebody String... du controller
voici le code du controllervoici celui de la 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
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
57
58
59
60
61
62
63
64
65
66
67
68
69 package com.agro.controller; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import com.agro.model.Depot; import com.agro.model.Fournisseur; import com.agro.model.Article; import com.agro.model.Magasin; import com.agro.service.ArticleService; import com.agro.service.DepotService; import com.agro.service.FournisseurService; import com.agro.service.MagasinService; @Controller @RequestMapping(value="/gestionArticle") public class ArticleController { @Autowired FournisseurService fournisseurService; @Autowired MagasinService magasinService; @Autowired DepotService depotService; @Autowired ArticleService articleService; @RequestMapping(value="/listeArticle", method= RequestMethod.GET) public String index(ModelMap model){ List<Article> listeArticle= articleService.getAllArticles(); List<Fournisseur> listeFournisseur = fournisseurService.getAllFournisseur(); List<Depot> listeDepot = depotService.getAllDepot(); List<Magasin> listeMagasin = magasinService.getAllMagasin(); model.addAttribute("listeArticle", listeArticle); model.addAttribute("listeFournisseur", listeFournisseur); model.addAttribute("listeDepot", listeDepot); model.addAttribute("listeMagasin", listeMagasin); return "article"; } @RequestMapping(value="/addArticle.do", method = RequestMethod.POST) public @ResponseBody String addArticle(String referenceArticle, String designation, String famille, String sousfamille, Double prixachat, Double prixmoyen, Double prixttc, String idDepot, String idMagasin, String idFournisseur){ Depot depot = depotService.getDepot(Integer.parseInt(idDepot)); Magasin magasin = magasinService.getMagasin(Integer.parseInt(idMagasin)); Fournisseur fournisseur = fournisseurService.getFournisseur(Integer.parseInt(idFournisseur)); Article art = new Article(depot, magasin, fournisseur, referenceArticle, designation, famille, sousfamille, prixachat, prixmoyen, prixttc); articleService.addArticle(art); return "ok"; } }
voici le resultat de la 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
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
57 <%@page import="java.util.ArrayList"%> <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <!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>Gestion Article</title> </head> <body> <fieldset> <legend>Article </legend> <center> <!-- formulaire pour ajouter un article --> <form action="<%=getServletContext().getContextPath()%>/gestionArticle/addArticle.do" method="post"> <table > <tr><td>Reference Article :</td><td><input type="text" id="referenceArticle" name="referenceArticle"></td></tr> <tr><td>designation :</td><td><input type="text" id="designation" name="designation"></td></tr> <tr><td>Famille :</td><td><input type="text" id="familleForm" name="famille"></td></tr> <tr><td>Sous famille :</td><td><input type="text" id="sousfamilleForm" name="sousfamilleForm"></td></tr> <tr><td>prix achat :</td><td><input type="text" id="prixachatForm" name="prixachatForm"></td></tr> <tr><td>prix moyen :</td><td><input type="text" id="prixmoyenForm" name="prixmoyenForm"></td></tr> <tr><td>prix ttc:</td><td><input type="text" id="prixttcForm" name="prixttcForm"></td></tr> <tr><td>stock initi :</td><td><input type="text" id="mailForm" name="mailForm"></td></tr> <tr><td>Depot :</td><td><select id="idDepot" name="idDepot"> <c:forEach items="${listeDepot}" var="depot"> <option value="${depot.idDepot}">${depot.adresseDepot}</option> </c:forEach></select></td></tr> <tr><td>Magasin :</td><td><select id="idMagasin" name="idMagasin"> <c:forEach items="${listeMagasin}" var="magasin"> <option value="${magasin.idMagasin}">${magasin.adresseMagasin}</option> </c:forEach></select></td></tr> <tr><td>Fournisseur :</td><td><select id="idFournisseur" name="idFournisseur"> <c:forEach items="${listeFournisseur}" var="fournisseur"> <option value="${fournisseur.idFournisseur}">${fournisseur.adresse}</option> </c:forEach></select></td></tr> <tr><td><input type="submit" value="ajouter"></td></tr> </table> </form> </center> </fieldset> <br> <center> <!-- liste des articles --> <table border="1" > <tr><td>Id</td><td>referenceArticle</td><td>famille</td><td>sous famille</td><td>prix achat</td></tr> <c:forEach items="${listeArticle}" var="article"> <tr><td>${article.idArticle}</td><td>${article.referenceArticle}</td><td>${article.famille}</td><td>${article.designation}</td><td>${article.prixachat}</td></tr> </c:forEach> </table> </center> </body> </html>
et voici le resultat lorsqu'on clique sur ajouter
Partager