Bonjour
je suis entrain de réaliser une application spring mvc , j ' ai un problème avec le contrôleur . quand j appuie sur lien create il me dirige pas sur bon url et j'ai un message d'erreur "Etat HTTP 404 - /WEB-INF/views/product/create.jsp"
voici le contrôleur
voici home page
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 @Controller @RequestMapping(value="/product") public class ProductEditController { @Autowired ProductRepository productRepository; public ModelAndView prepareModelAndView(Product product){ ModelAndView mv = new ModelAndView("edit"); /*jsp*/ mv.addObject("id", product.getId()); mv.addObject("product", product); return mv; } @RequestMapping("/create") public ModelAndView createProduct(){ return prepareModelAndView(new Product()); } @RequestMapping("/edit") public ModelAndView updateProduct(@RequestParam ("id") Long id){ Product product = productRepository.findById(id); return prepareModelAndView(product); } @RequestMapping(value="/editsubmit",method=RequestMethod.POST) public ModelAndView addProductOnSubmit(@Valid @ModelAttribute("Product") Product product, BindingResult bindingResult){ if(bindingResult.hasErrors()){ return new ModelAndView("edit","product", product); } if(product.getId() != null){ productRepository.create(product); }else{ productRepository.update(product); } return new ModelAndView("redirect:/product/edit"); } @RequestMapping("/delete") public ModelAndView deleteProduct(@RequestParam ("id") Long id){ Product product = productRepository.findById(id); if(product != null) productRepository.delete(id); return new ModelAndView("redirect:/listproduct"); /*jsp*/ } }
voilci le fichier 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 !DOCTYPE html > <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@taglib uri="http://www.springframework.org/tags" prefix="spring" %> <%@taglib uri="http://www.springframework.org/tags/form" prefix="form" %> <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <html lang="fr"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta charset="utf-8"> <title>Ecommerce project</title> </head> <body> <form action="" method="post"> <li><a href="<c:url value='/product/create'/>"> Create </a></li> <li><a href="productlist">Lister</a></li> </form> </body> </html>
voici le dispatcher
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 <?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>ECommerceProject</display-name> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <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>
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 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"> <context:annotation-config /> <context:component-scan base-package="be.ecommerceproject.controller"> </context:component-scan> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix"> <value>/WEB-INF/views/</value> </property> <property name="suffix"> <value>.jsp</value> </property> </bean> </beans>
Partager