Spring : annotation controller
Bonjour
voila je suis nouveau sur Spring je viens de faire une petite application web simple avec une page web, un controleur, web.xml et un fichier de conf spring. pour tester les annotations controllers,j'ai suivi toutes les étapes mais la méthode du controleur ne s'execute jamais, je pense que j'ai un problème dans le context ou un truk comme ça . Voila le code.
Controller
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
package com.mvc;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class controler {
@RequestMapping("/*")
public String setupForm() {
System.out.println("test reussi");
return "redirect:file.jsp";
}
} |
Conf-servlet.xml
Code:
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
| <?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
<a href="http://www.springframework.org/schema/beans/spring-beans-2.5.xsd" target="_blank">http://www.springframework.org/schem...-beans-2.5.xsd</a>
<a href="http://www.springframework.org/schema/context" target="_blank">http://www.springframework.org/schema/context</a>
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:annotation-config/>
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
<context:component-scan base-package="com.mvc"/>
<bean id="internalViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans> |
web.xml
Code:
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
| ........................
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/conf-servlet.xml</param-value>
</context-param>
<servlet>
<servlet-name>conf-servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/conf-servlet.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>conf-servlet</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
</web-app> |
normalement en cliquant que n'importe quel lien jsp la methode setupForm() dans le controler doit s'executer et afficher "test reussi" mais il se passe rien
quelqu'un peut m'expliquer ça s'il vous plait....