Bonjour,
J'essaie de mettre en place un projet JEE avec Spring MVC mais j'ai le message d'erreur suivant :
Voici ce que je faisEtat HTTP 404 - /learning/create
type Rapport d''état
message /learning/create
description La ressource demandée n''est pas disponible.
Le contrôleur :
web.xml :
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 package com.learning.controller; import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.portlet.ModelAndView; import com.learning.model.Lieu; import com.learning.model.Trainer; import com.learning.repository.LieuRepository; @Controller @RequestMapping("/learning") public class LieuController { @Autowired private LieuRepository lieuRepository; private ModelAndView prepareModelAndView(Lieu lieu ) { ModelAndView mv = new ModelAndView("edit"); mv.addObject("id", lieu.getId()); mv.addObject("lieu", lieu ); return mv; } @RequestMapping("/create") public ModelAndView lieuCreate() { return prepareModelAndView(new Lieu()); } @RequestMapping("/edit") public ModelAndView lieuEdit (@RequestParam("id")long id) { Lieu lieu= (Lieu)lieuRepository.findById(id); return prepareModelAndView(lieu); } @RequestMapping(value="/addOnsubmit",method=RequestMethod.POST) public ModelAndView LieuAddSubmit( @Valid @ModelAttribute Lieu lieu,@Valid @ModelAttribute Trainer trainer, BindingResult bindingResult){ if (bindingResult.hasErrors()){ return new ModelAndView ("edit","lieu",lieu); } if(lieu.getId()!=null) { lieuRepository.merge(lieu); } else { lieuRepository.persist(lieu); } return new ModelAndView("redirect:/displaylieu"); } @RequestMapping("/delete") public ModelAndView lieuDelete(@RequestParam("id")long idlieu) { Lieu lieu = (Lieu)lieuRepository.findById(idlieu); if (lieu!= null ){ lieuRepository.delete(idlieu); } return new ModelAndView("redirect:/displaylieu"); } }
home page(web-inf/views/index.jsp) :
Code xml : 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 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <display-name>Learning_Spring00</display-name> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/dispacher-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!-- le chargeur du contexte de l'application --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/classes/applicationContext.xml</param-value> </context-param> <filter> <filter-name>JpaFilter</filter-name> <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class> </filter> <filter-mapping> <filter-name>JpaFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
web-inf/views/edit.jsp :
Code html : 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 <%@ 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"%> <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%> <!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>Insert title here</title> </head> <body> <form:form action=" " method=""> <div> <ul> <li><a href="/learning/create">Ajout</a></li> <li><a href="<c:url value='/learning/create'/>"> Créer </a></li> <li><a href="<c:url value='/learning/edit'/>"> add </a></li> </ul> </div> </form:form> </body> </html>
Quelqu'un saurait-il m'indiquer comment résoudre ce problème ?
Code html : 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 <%@ 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"%> <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%> <!DOCTYPE html > <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>place</title> </head> <body> <form:form action='<%=response.encodeURL("/addOnsubmit")%>'modelAttribute=lieu" method="post"> <form:hidden path="id"/> <label>Name</label> <form:input path="name" /> <form:errors path="name" /><br> <label>Street</label> <form:input path="street" /> <form:errors path="street" /><br> <input type="submit"value="<c:choose><c:when test="${lieu.id==null}">Add </c:when><c:otherwise>Edit</c:otherwise></c:choose>"/> </form:form> </body> </body> </html>
merci pour votre aide
Partager